Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Child table with new Identity Value

Status
Not open for further replies.

xterra

Programmer
Apr 5, 2001
71
US
I have 2 tables. The parent table has an ID field that is automatically generated when a record is added. The child table ties its records to the main table using that ID field.

I am trying to convert some data into these tables. my problem is that when I import the data into the main table it will recieve a new ID # that I need to update to all the records in the child table. how can I do this?

Thanks,

Adam
 
Create a trigger which update the Child table's ID to be the latest auto incremented number.

Create Trigger tr_Parent on Parent for insert
as
DECLARE @ID int
SELCT @ID = ID From inserted
update Child Set ID = @ID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top