OUTPUT INTO (SQL Server)
OUTPUT INTO (SQL Server) is a SQL statement in the DML Statements category. SQL Server: captures DML results into a table variable or temp table for further processing. The syntax is DELETE/UPDATE/INSERT ... OUTPUT deleted.* INTO @tableVariable;. It returns dML results into variable. A typical example: DECLARE @deleted_emps TABLE (id INT, name VARCHAR(100)); DELETE FROM employees OUTPUT deleted.id, deleted.name INTO @deleted_emps WHERE department = 'Temp'; SELECT * FROM @deleted_emps; -- Deleted rows are now available in the table variable -- Can be used for auditing, archiving, or further processing -- INSERT with OUTPUT: INSERT INTO employees (name, salary) OUTPUT inserted.id, inserted.name VALUES ('Alice', 75000); A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows.