
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 four articles, we’ll cover the following basic topics.
- What is the Merge statement and how do you use it?
- Using Merge in more advanced ways such as auditing and data comparisons between tables.
- How to use Merge to load slowly changing Dimensions.
- How to use a script I wrote to take the tedium out of writing T-SQL Merge statements.
Upcoming Presentation
If you’re in the area, I’ll be presenting on T-SQL Merge this week, Wednesday 7/18, for the Forth Worth SQL Server User Group at 7pm. Anyone who has seen me present knows that I like the audience to have a good time, and this session will be no different. The abstract is below.
Have you got the Urge to Merge?
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, generally outperforming separate statements. Fewer know, however, that it can be used to load slowly changing dimensions, facilitate auditing, and for many other uses. Come to the user group meeting and learn the in and outs of T-SQL Merge. I’ll even show you how to write complex Merge statements with lightning speed.
Hope to see some of you folks there.



Popular Articles