April 16, 2024

Output Clause

Output Clause (T-SQL)

Output Clause (T-SQL):

The OUTPUT clause in T-SQL is a powerful feature that allows you to retrieve information about rows affected by INSERT, UPDATE, DELETE, or MERGE statements. This information can be used for purposes like confirmation messages, auditing, or archiving. You can also insert the results into a table or table variable for further processing.

The OUTPUT clause can be used with the following SQL statements:

  • INSERT
  • UPDATE
  • DELETE
  • MERGE

When performing an INSERT operation, the OUTPUT clause can capture values from the newly inserted rows, such as identity column values or computed columns. Similarly, during a DELETE operation, it can retrieve details about the deleted rows. The syntax for the OUTPUT clause is as follows:


OUTPUT { [DELETED.] * | [INSERTED.] * | column_name [AS alias] }
INTO target_table

      

No comments:

Post a Comment