get inserted id sql code example
Example 1: how to get inserted id in sql
INSERT INTO TableA (...) VALUES (...)
SET @LASTID = SCOPE_IDENTITY()
INSERT INTO TableA (...) VALUES (...)
SET @LASTID = @@IDENTITY
SET @LASTID = IDENT_CURRENT('TableA')
DECLARE @NewIds TABLE(ID INT, ...)
INSERT INTO TableA (...)
OUTPUT Inserted.ID, ... INTO @NewIds
SELECT ...
Example 2: how to get inserted id in sql server
SELECT SCOPE_IDENTITY();
Example 3: get last inserted primary key
INSERT INTO dbo.Table(columns)
OUTPUT INSERTED.p_key, INSERTED.someothercolumnhere .......
VALUES(...)