The MERGE Statement
The new MERGE statement in SQL Server 2008 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. That’s right—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 new T-SQL feature), as you’ll see later in this chapter.
In earlier versions of SQL Server, separate multiple statements were required to achieve what can now be accomplished with a single MERGE statement. This new statement has a flexible syntax that allows us to exercise fine control over source and ...
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