I have a table with an auto-incrementing identity column. Typically I might insert data as follows
INSERT INTO [dbo].[table]
DEFAULT VALUES;
SET @value = SCOPE_IDENTITY();
This way I know the identity value I've just inserted. However I need to insert a "set" of values into that table. Preferably also be able to identify the values I just inserted. I was hoping something similar to the following would be possible ...
INSERT INTO dbo.table DEFAULT VALUES
OUTPUT INSERTED.id INTO @output
SELECT SCOPE_IDENTITY() -- obviously this isn't possible and doesn't actually make sense
FROM @records
WHERE somecolumn IS NULL
I know I might need to set identity_insert on
... I would prefer not to if I don't have to. I am also aware that maybe I could also use some sort of recursive CTE, though I haven't used one of those in a while. Any help would be appreciated.
EDIT: to be clear the question I am asking is: how do I insert a "SET" of data into a table with an auto-incrementing identity column. And hopefully identify the values I just inserted in some way.