Results 1 to 4 of 4

Thread: Need SQL query

  1. #1
    Join Date
    Nov 2008
    Posts
    117

    Unanswered: Need SQL query

    Hi,
    I need an SQL query as i am not strong in building queries.
    CreateUser Table
    UserID (Primary Key, AutoNumber)
    UserName (Text)
    more fields to be added....

    Login Table
    LoginID
    more fields to be added....

    Profile Table
    ProfileID (i will add more fields here)
    more fields to be added....


    When i add some username in createuser table, UserID will be automatically generated and a new record is created.
    So after once the record is created in createuser, i want LoginID(Login table) and ProfileID(Profile table) fields to be updated with the same UserID from tbl_createuser with the remaining fields set to be null in login table and profile table.

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    In the "Login table" create a UserID feild
    and in the "Profile Table" create a UserID feild

    Then When you adding data to the Login table or the Profile table you should be passing the UserID also then you will have a link to all tables
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Nov 2008
    Posts
    117
    Can u make me more clear with some samples pls?

  4. #4
    Join Date
    Oct 2009
    Posts
    27
    In the procedure declare one variable @USERID

    declare @USERID int

    After the insert statement to "CreateUser" table add the following script line.

    set @USERID=scope_identity()
    select @USERID

    Here the @USERID have the last inserted records UserID column value.So use this @USERID varable to insert the records to other 2 tables something ike this,

    insert into Login (USERID) values(@USERID)

    insert into Profile (USERID) values(@USERID)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •