:::: MENU ::::

Posts Categorized / Merge Statement

  • Nov 27 / 2008
  • 0
dbDigger, Merge Statement, T-SQL Enhancements, T-SQL Interview Questions

operations performed by MERGE statement in SQL Server 2008

Question:
Which of the following operations can be performed by MERGE statement in SQL Server 2008?

Answer:

  • WHEN MATCHED
  • WHEN NOT MATCHED BY TARGET
  • WHEN NOT MATCHED BY SOURCE

Explanation:
Merge is used to check if values match in both Source and Target, which is equal to WHEN MATCHED and an UPDATE is fired. When value exist in SOURCE table but not in TARGET table then WHEN NOT MATCHED [ BY TARGET ] then INSERT the new value and if the value exist in TARGET and not in SOURCE then WHEN NOT MATCHED [BY SOURCE] and DELETE is fired.

Ref: Merge – http://msdn.microsoft.com/en-us/library/bb510625.aspx

Note: The Question is taken from SQLServercentral.com.

Consult us to explore the Databases. Contact us