Using an OUTPUT clause with an INSERT statement
The following is an example of using the OUTPUT clause with an INSERT statement.
This can be useful when it is necessary to know the ID values (identity or unique identifiers) that were inserted into a table.
DECLARE @TableIDs table (
ID int
, uuid uniqueidentifier
)
INSERT into Table1 (TextInfo1, IntInfo2, uuid )
output inserted.Id as ID, inserted.uuid as uuid into @TableIDs (ID, uuid)
values
('hi there', 5, newid())
, ('hello world', 8, newid())
-- output our table of ID values.
select * from @TableIDs
Last modified by Mohit @ 4/4/2025 5:16:43 PM