The SQL Server MERGE command is the combination of INSERT, UPDATE and DELETE commands consolidated into a single statement. Here is how to get started with the use of MERGE into in SQL Server:

  1. Start off by identifying the target table which will be used in the logic.
  2. Next, identify the source table which will be used in the logic.
  3. Determine the appropriate search conditions in the ON clause in order to match rows.
  4. Specify logic when records are matched or not matched between the target and source i.e. comparison conditions.
  5. For each of these comparisons, conditions code the logic. When matched, generally an update condition is used. When not matched, generally an insert or delete condition is used.

However, SQL Server provides the statement that allows you to perform three actions at the same time. The following shows the syntax of the MERGE statement:


You may like How to Split comma delimited strings into a Table in SQL Server.

Use Merge Into in SQL Server

The article was published on November 7, 2015 @ 6:06 PM

Leave a Comment