0

-- DUPLICATE OF Best way to get identity of inserted row? --

Well, I got an hard time finding a good title for this one.

I have two tables, with microsoft SQL server. Here's the structure:

TableA ( Id identity, Name varchar(20))
TableB ( Id identity, Name varchar(20))
Mapping ( IdTableA int, IdTableB int)

On TableA, I have an After Insert trigger. I want to "replicate" the insert into TableB, gets the new Ids and insert the mapping between the TableA's id and the TableB's id into the table Mapping.

I have no problem with inserting the data into TableB... but I have an hard time finding how to create a "map" between the two Ids...

Any help would be very appreciated.

Community
  • 1
  • 1
vIceBerg
  • 4,197
  • 5
  • 40
  • 53
  • I know I can do this using Cursor or a While loop, but EVERYBODY says that's an option to totally avoid. – vIceBerg Jul 08 '13 at 18:48
  • I found the answer elsewhere in SO http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row – vIceBerg Jul 08 '13 at 19:16

0 Answers0