I am using SQL statement like
INSERT INTO TableName (col1, col2, col3)
VALUES
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
Is there a way to get the list of all newly inserted rows?
I am using SQL statement like
INSERT INTO TableName (col1, col2, col3)
VALUES
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
Is there a way to get the list of all newly inserted rows?
Yes - if you're on SQL Server 2005 or newer - use the OUTPUT clause!
INSERT INTO TableName (col1, col2, col3)
OUTPUT Inserted.ID, Inserted.col1
VALUES
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3)
This will output the ID and col1 column for all new rows inserted.