The T-Sql Merge statement, introduced in SQL 2008, is powerful, versatile, and performant. However, it is also one of T-SQL’s least understood statements. Most DBAs know they can use it to insert, update, and delete data in a target table in a single transaction, which generally outperforms separate statements. Fewer know, however, that it can be used to load slowly changing dimensions, facilitate auditing, as well as other uses. I briefly discussed how to use Merge some time ago, but I wanted to take a deeper dive into it because it is so darn usefull.
Though the statement is documented on many sites, many tend to cover it tersely or are little more than variations on Books Online, which I find difficult to read and absorb. So, in the following articles, we’ll cover the following basic topics.
- This post represents my original attempt, and I leave the link here for tracking purposes, but most people should skip it in favor of the second link.
What is the Merge statement and how do you use it?
- Writing T-SQL Merge Statements the Right Way
- Using the Output Clause with T-SQL Merge
- What exactly are Dimensions and Why do They Slowly Change?
- How to Properly Load Slowly Changing Dimensions using T-SQL Merge
- Related: Loading Dimensions Historically
- Related: Extracting Historical Dimension Records using T-SQL
- Data Warehouse Initial (Historical) Dimension Loading With T-SQL Merge