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!

Insert to two related tables

Status
Not open for further replies.

zatch

MIS
Oct 11, 2001
75
US
I need to run a query which inserts to two related tables where the parent table has an identity field.

Table A - Employer
Employer_Id (Identity Field)
First_Name
Last_Name

Table B - Employee
Employer_Id (Foreign Key)
First_Name
Last_Name

I have no problem selecting and inserting the data into Table A, the problem I'm having is that I don't know how to then grab the newly created Employer_Id from this table so that I can use it to insert the record(s) into Table B.

Any help is greatly appreciated.

Zatch
 
Since it looks as if this is an employee table, I would guess there would not be "too" many inserts going on.

What you could do is use scope_identity() to pull the new ID and use it in the insert into table 2 OR you could create an INSERT Trigger on table1

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top