How to implement a foreign key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karsoumitra
    New Member
    • Aug 2006
    • 1

    #1

    How to implement a foreign key

    Hello,

    I am facing a problem, I have a table and the primary key of this table is a foreign key of another table. I want to insert data into the mother table, and at the same time i want to insert data into the child table depending on the last inserted row of the mother table. So I need 2 insert commands to run. But I think data inconsistency may happened. When i insert into the second table, then the mother table may be updated. Primary key of the mother table is declared as identity column. Can anyone suggest me how i can insert into those two tables.
  • xtron
    New Member
    • Aug 2006
    • 4

    #2
    I think you should use stored procedure which do some operations like this:

    1) insert to mother table
    2) use @@IDENTITY to get identity value last inserted row
    3) insert to the second table

    Comment

    Working...