OUTPUT CLAUSE
OUTPUT returns a result set of the rows inserted, updated or deleted.
Delete rows and return the rows deleted.
DELETE <schema>.<table_name>
OUTPUT DELETED.*
OPTIONAL FROM, JOIN, WHERE, etc.
MERGE
You can access the $action column in the OUTPUT. It is an NVARCHAR(10) that returns 'INSERT', 'UPDATE', or 'DELETE' for each row of the OUTPUT.
You can use WITH (READPAST) on UPDATE and DELETE statements when multiple processes can perform a destructive read.
INSERT Example
INSERT <table_name>
(<column_list>)
OUTPUT INSERTED.<colname(s)> INTO <table_name>
VALUES (<value_list>)
UPDATE Example
UPDATE <table_name>
SET <colN> = <value>
OUTPUT
INSERTED.<colname>, DELETED.<colname>
INTO <table_name>
OPTIONAL FROM, WHERE, etc.
Comments
Post a Comment