Lesson 40. Loading Tables With MERGE
The MERGE clause is the most powerful SQL clause known to man. With MERGE, you can take data from one table and load it into another table. Unlike INSERT INTO SELECT, MERGE gives you way more power in how you go about doing that.
With great power comes great complexity and a full explanation of SQL MERGE is FAR outside the scope of this tutorial.
The most common use case I have for MERGE is loading Type II slowly changing dimensions in data warehouses. I talk about this extensively in the section titled Loading A Type II Slowly Changing Dimension With SQL Merge.
The process of using MERGE works like this.
Identify the table you will load data into.
Identify the table that you will use as the source of your data.
Identify how records in those two tables are connected.
Give instructions on what to do when records do not match.
Give instructions on what to do when records do match.
Examples
A Basic MERGE Example
In [ ]:
Last updated