Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

output $action in Merge statement in Sql server 2008? [closed]

what is the use of output $action in Merge statement in Sql server 2008?

like image 516
Naveenkumar Avatar asked May 20 '11 17:05

Naveenkumar


People also ask

Can we use CTE in MERGE statement?

You can also use a CTE in a CREATE a view, as part of the view's SELECT query. In addition, as of SQL Server 2008, you can add a CTE to the new MERGE statement. After you define your WITH clause with the CTEs, you can then reference the CTEs as you would refer any other table.

How do you fix the MERGE statement attempted to update or DELETE the same row more than once?

A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.

Does MERGE DELETE rows?

A single MERGE statement can also combine both DELETE and INSERT operations, or can combine both UPDATE and INSERT operations without deleting any rows. The source table is unchanged by the MERGE statement.


1 Answers

The all-knowing MSDN says

$action

Is available only for the MERGE statement. Specifies a column of type nvarchar(10) in the OUTPUT clause in a MERGE statement that returns one of three values for each row: 'INSERT', 'UPDATE', or 'DELETE', according to the action that was performed on that row.

like image 150
SLaks Avatar answered Sep 27 '22 23:09

SLaks