Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    4

    Unanswered: Insert Data into Related Tables

    i am using ms sql server 2005 express for the following:

    T1 = {t1.c1(PK), t1.c2, t2.c1(FK)}

    T2 = {t2.c1(PK), t2.c2}

    where T1 and T2 are tables from the same database, and tn.cn are CoulmnN of TableN
    T1 and T2 are linked by the relationship t2.c1

    i need to know how to add records to T1 and T2 using ms sql.

    record for T2 needs to be added first then retreive t2.c1 from T2 to add record to T1 with t1.c1, t1.c2 t2.c1

    please help, thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use SCOPE_IDENTITY() function right after the insert to T2

    use this value for the insert to T1

    examples are in the manual

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2008
    Posts
    4
    thank you my friend. i will try that now!

Posting Permissions

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