YOUR AD GOES HERE

Learn T-SQL With Erik: A Neat Thing with MERGE and OUTPUT

Published 24, Jul 2025

Erik Darling (Erik Darling Data)


Description:
In this video, I dive into an intriguing aspect of T-SQL using the 'MERGE' statement and its 'OUTPUT' clause, showcasing a feature that isn't available with regular 'INSERT' statements. I demonstrate how to use 'MERGE' in SQL Server Management Studio 21 (version 21.something.6.3) to perform an insert operation on a target table while modifying the source data in ways you can't achieve with a standard 'INSERT'. By creating sample tables and inserting data, I illustrate how the 'OUTPUT' clause of 'MERGE' allows us to see both the original values from the source and the new values inserted into the target table. This is particularly useful for tracking changes or maintaining historical records in complex processes. I also highlight why this isn't possible with a regular 'INSERT', emphasizing the unique capabilities that 'MERGE' offers, which can be incredibly valuable for detailed data manipulation tasks.

CHAPTERS

00:00:00 - Introduction
00:00:29 - Entertaining Content
00:00:59 - Sample Data Creation
00:01:29 - Table Definitions
00:01:59 - Merge Query Setup
00:02:15 - No Serializable Hint
00:02:31 - Multiple Actions
00:02:40 - Merge Statement Details
00:03:00 - Output Clause Explanation
00:03:27 - Action Column
00:03:59 - Output Syntax
00:04:04 - Inserted Table Columns
00:04:18 - Source Values Column
00:04:32 - Output Results
00:05:25 - Complicated Processes
00:05:32 - Normal Insert Comparison
00:05:40 - SQL Server Error
00:06:09 - Merge vs. Normal Insert
00:06:19 - Useful for Query Patterns
00:06:44 - Conclusion

━━━━━━━━━━━━━━━━━━━━━━━━━━
???? TRAINING & COURSES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Get AI-Ready With Erik
https://training.erikdarling.com/get-ai-ready-with-erik?coupon=AIREADY

SQL Server Performance Engineering Course
https://training.erikdarling.com/sql-server-performance-engineering?coupon=ENGINEERING

Learn T-SQL with Erik
https://training.erikdarling.com/learn-t-sql-with-erik?coupon=ADVANCEDTSQL

Everything Bundle:
https://training.erikdarling.com/?coupon=SPRINGCLEANING

━━━━━━━━━━━━━━━━━━━━━━━━━━
????️ CONSULTING & SERVICES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Need SQL Server performance help?
https://training.erikdarling.com/sqlconsulting

━━━━━━━━━━━━━━━━━━━━━━━━━━
???? CONNECT
━━━━━━━━━━━━━━━━━━━━━━━━━━
Ask questions at Office Hours
https://erikdarling.com/officehours/

Become a channel member
https://www.youtube.com/@ErikDarlingData/join
━━━━━━━━━━━━━━━━━━━━━━━━━━

Releted More Videos

You May Also Like

YOUR AD GOES HERE

YOUR AD GOES HERE