Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two table, tblA and tblB. which are useing primary key (tblA) with identity (1,1) and foreign key in tblB of tblA primary key.

and i wont to effect this two table in single store processor with using trans commit. so

here i confused, how can i called recent inserted row id of in tblA for table tblB row effect.
Posted

1 solution

Start the transaction.
INSERT the row in tblA.
Use @@IDENTITY[^] to retrieve the new value.
INSERT the row in tblB
Commit the transaction.
 
Share this answer
 
Comments
ZurdoDev 15-Aug-14 11:21am    
SCOPE_IDENTITY() is actually preferred. It has more specific scope.

http://msdn.microsoft.com/en-us/library/ms190315.aspx
OriginalGriff 15-Aug-14 11:36am    
Are you asking me to come round and press the keys for you?
What part do you not know how to do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900