Merge replication is a method for copying and distributing data and database objects from one SQL Server to one or more SQL Servers and synchronizing the database for consistency.
A main characteristic of merge replication is that permits both the publisher (primary) and subscriber (secondary) servers to modify the data independently. Merge agents pre-configured conflict resolution mechanism kicks in to solve any data conflicts synchronize all changes. Version related data conflicts are common with merge replication because updates to the database happen irregularly when there is a connection between the publisher and subscriber.
Merge replication is implemented by the SQL server Snapshot agent and merge agent. When we configure merge replication the snapshot agent takes one snapshot and it will put in repaldata folder then the merge agent applies snapshot to the subscriber. And merge agent merges any data changes that occurred at the publisher or subscriber after the initial snapshot was taken.
Implementation of Merge Replication:
First create local publication in publisher SQL server instance
Go to replication folder in SQL server instance and expand replication.
Right click on local publication and select new publication.
Click On Next
Select publication database from which database objects you want to replicate objects to subscription database.
Click on next.
Select publication database from which database objects you want to replicate objects to subscription database.
Click on next.
Select objects (tables, functions, stored procedures) which you want to replicate from publisher to subscriber.
Click on next
Click on next.
If want to do any filtering you can do from this window.
Otherwise, click on next.
Select create snapshot immediately.
If you want you can select schedule the Snapshot agent to run at the following times and you can schedule the time dependents on your requirement.
Click on next.
In this window you can configure snapshot agent.
To configure click on security settings.
Here I am selecting SQL server agent as snapshot agent.
If you have separate user account for snapshot agent select Run under the following windows account and Give the agent account name and password.
Click on OK.
Click on next.
Select create the publication option.
Click on next.
Give the publication name whatever you want.
Click on finish
Publication was created successfully.
Now go to subscriber SQL Server instance and create subscriber.
Go to replication folder in SQL server instance and expand replication.
Right click on local subscriptions
Select new subscriptions.
Click on next.
Connect to the publisher server.
To connect scroll down the publisher and choose the publisher server and click on connect.
After connecting to the publisher you will get below window.
Select publication and click on next.
In this window you need to select merge agent location.
If you select push subscription merge agent runs at distributor.
If you select pull subscription merge agent runs at subscriber.
Select one option and click on next.
Select subscriber and subscription database if already is there ,otherwise select new database and give name click on ok .
Click on next.
To configure merge agent click on the connection to subscriber.
Here I am selecting SQL server agent as snapshot agent.
If you have separate user account for snapshot agent select Run under the following windows account and Give the agent account name and password.
Click on OK.
Click on next.
\
Select agent schedule run continuously.
Click on next.
Select initialize immediately.
Click on next.
Select subscription type is server.
Click on next
Select create the subscriptions.
Click on next.
Click on Finish.
Subscription created successfully.
Configuration of Merge replication completed successfully.