Part 69 Merge in SQL Server
Link for all dot net and sql server video tutorial playlists Link for slides, code samples and text version of the video What is the use of MERGE statement in SQL Server Merge statement introduced in SQL Server 2008 allows us to perform Inserts, Updates and Deletes in one statement. This means we no longer have to use multiple statements for performing Insert, Update and Delete. With merge statement we require 2 tables 1. Source Table Contains the changes that needs to be applied to the target table 2. Target Table The table that require changes (Inserts, Updates and Deletes) The merge statement joins the target table to the source table by using a common column in both the tables. Based on how the rows match up as a result of the join, we can then perform insert, update, and delete on the target table. Merge statement syntax MERGE TARGET AS T USING SOURCE AS S ON
|
|