views:

54

answers:

3

Hi, Merge can performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table.

Is anyone familiar with the performance to use "Merge" versus the traditional logic to check existence and decide the update or insert then?

Thanks!

+2  A: 

MERGE is generally faster because there are less DML operations, and it's also the recommended approach from the documentation. With the "traditional" way, you're processing the tables twice - once to check for existence and once to execute your DML. With MERGE, everything is encapsulated with one operation - hence one set of locks issued, one set of logging, etc. etc.

However, it is pretty subjective on what your queries are actually doing. You should probably take a look at Optimizing MERGE Statement Performance on MSDN.

womp
+1  A: 

Technet has some information in Optimizing MERGE Statement Performance. It basically says that performance is better than doing individual checks, because only one pass over the data is required. However indexes etc. are of course still important.

Anders Abel
A: 

Hi, We used this Merge statement recently in a large Data Warehouse project and we found a good performance as well as easy of implementation. We feel Merge statement is very handy for development.

looking forward to discuss

thanks prav

praveen

related questions