OUTPUT

Examples:

--insert example
DECLARE @tabvar1 TABLE (a INT, b INT);

INSERT INTO @tabvar1 (a, b)
VALUES (0, 0), (1, 1), (2, 2);

SELECT * FROM @tabvar1;

DECLARE @tabvar2 TABLE
(a INT, b INT);

INSERT INTO @tabvar2 (a, b)
VALUES (3, 3), (4, 4);

SELECT * FROM @tabvar2;

INSERT INTO @tabvar1 (a, b)
       OUTPUT Inserted.a AS InsertedA, inserted.b AS InsertedB
       SELECT a, b
       FROM @tabvar2
       WHERE a > 3;

SELECT * FROM @tabvar1;
--update example
DECLARE @xtablevar1 TABLE (x INT, y INT);

INSERT INTO @xtablevar1 (x, y)
VALUES (0, 0), (0, 1), (3, 2);

SELECT * FROM @xtablevar1;

UPDATE @xtablevar1
    SET x = 1
OUTPUT inserted.x AS outputx,
       inserted.y AS outputy
WHERE y < 2;

SELECT * FROM @xtablevar1;
-- delete example with a WHERE clause
DELETE FROM <source_table>
OUTPUT DELETED.<column_list>
INTO <destination_table>.(<column_list>)
WHERE <where_clause>