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.