Inserting Primary Key of Parent Table in to both child table

  • Hello,

    I want to insert primary key value into two chil table when a record intert in to parent, an of that parent table in to both child table who have foreign key of parent table in to both child table. Any idea how to do this?

  • If I understand you correctly, I believe what you may want to have a look at is cascading inserts:

    http://www.dba-sql-server.com/sql_server_tips/t_super_sql_423_cascade.htm

  • Hello,

    First thanks for reply my post....

    In this case I can add only data which was inserted in table b , while the foreign key of that table , must match with primary key value of table a.

    My case is little different, like when any value inserted in table a, the primary key of that record goes in to table b, not the data. so i need trigger as seems. can you give me example of it so that i create own trigger for my table.

  • Answer this, what is the table that only has a PK <and possibly no fk>.

    This is where you do the first insert.

    Then you can insert in the child tables.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply