1/* inserted id in SQL Server */
2-- SCOPE_IDENTITY() last identity generated for ANY TABLE in the CURRENT SESSION and the CURRENT SCOPE
3 INSERT INTO TableA (...) VALUES (...)
4 SET @LASTID = SCOPE_IDENTITY()
5-- @@IDENTITY last identity generated for ANY TABLE in the CURRENT SESSION
6 INSERT INTO TableA (...) VALUES (...)
7 SET @LASTID = @@IDENTITY
8-- IDENT_CURRENT('TableA') last identity for a SPECIFIC TABLE in ANY SESSION and ANY SCOPE
9 SET @LASTID = IDENT_CURRENT('TableA')
10-- OUTPUT clause of the INSERT statement EVERY ROW inserted via that STATEMENT
11 DECLARE @NewIds TABLE(ID INT, ...)
12 INSERT INTO TableA (...)
13 OUTPUT Inserted.ID, ... INTO @NewIds
14 SELECT ...