sql get id of inserted row code example
Example 1: sql insert inserted id
DECLARE @Ids_tbl TABLE ([id] INT);
INSERT INTO [sometable] ([ColA],[ColB])
OUTPUT INSERTED.ID INTO @Ids_tbl(id)
VALUES ('valA','valB');
SELECT [id] FROM @Ids_tbl;
Example 2: 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 3: mysql id of inserted row
INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
SELECT LAST_INSERT_ID();