JOB + MERGE synchronize data across servers

Source: Internet
Author: User


To solve the pressure on a single server, the database and sub-server are deployed, 
but the table data synchronization originally implemented by the trigger cannot be achieved.
 Because the boss of the Director is not allowed to start the distributed transaction (MSDTC), 
I do not want to copy and subscribe to a few thousand lines of basic data.
 Therefore, we decided to use the JOB + MERGE Method for implementation. 
Create procedure PRC_SYNC_DATAASBEGINSET nocount on -- synchronize A to B across databases and servers (table A and table B have the same structure)
 -- if the conditions are the same, merge [guagua_vas_statistics] will be inserted if the updates are different. [dbo]. [t_base_goods] t -- target table to be updated: using [192.168.1.75, 18991]. [guagua_goods]. [dbo]. [t_base_goods] s
 -- source table on t. base_goods_id = s. base_goods_id -- update condition (that is, the primary key) when matched --
 if the primary key matches, update then update set t. name = s. name, t. unit_name = s. unit_name, t. depletable = s. dep Letable ,.......
 when not matched then insert values ([base_goods_id], [name], [unit_name], [depletable],...) when not matched by source then delete; 
-- delete a record that is not in the source in the target. The END cannot be omitted by source.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.