Programmer's Rules

Transact-SQL

How to use the OUTPUT clause to monitor data changes in SQL Server

Concise information on OUTPUT clause usage in Transact-SQL

Transact-SQLjob interviewSQL Server70-761

OUTPUT clause provides a confirmation message after INSERT, UPDATE, DELETE or MERGE statements.

The results of OUTPUT can be sent to a client application or inserted into a table or a table variable.

The following example returns the all inserted rows of INSERT as a client message:

The output is:

CurrencyCode Name
ABC ABC

The next example will populate a table with the UPDATE statement results:

The result of the SELECT statement:

is:

CurrencyCodeDeleted CurrencyCodeInserted
ABC CBA

The below code shows how to insert results of OUTPUT statement into a table variable:

The result of the query:

is:

CurrencyCodeDeleted
CBA
Tutorial statistics