The MERGE Statement
The MERGE statement does just what its name says. It combines the normal insert, update, and delete operations involved in a typical merge scenario, along with the select operation that provides the source and target data for the merge. Essentially, that means it combines four statements into one. In fact, you can combine five statements into one using the OUTPUT clause, and even more than that with INSERT OVER DML (a special T-SQL feature syntax, which we cover next).
Prior to SQL Server 2008, separate, multiple statements were required to achieve what can now be accomplished with a single MERGE statement. This statement has a flexible syntax that allows you to exercise fine control over source and target matching, as well ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access