August 27, 2011

MERGE in SQL Server

Using MERGE operator we can easily synchronize two tables based on their differences.
It performs DML operations on target table based on the results of join of two tables.
For better understanding I am trying to put an example here.
We have a table ContactStaus with below structure.



Inserting some sample data:





Now on weekly basis we receive some updated data and what we do
update status of matched contact number,delete some specified contact
and insert if we receive new contact.



Let suppose we have following data in our Updatecontactstatus.



We have MERGE operator in SQL Server we can do all three activities Insert,Delete and Update
in a more better way in this type of situation.




See results we have managed ContactStaus table synchronization in a better way.
That’s It.
Enjoy Learning.

No comments:

Post a Comment