CWAPI - Charlie Wang API

特定条件下,同步两个SQL Server数据库数据

MSSQL Tips Charlie Wang 1244℃

在同时使用多个SQL SERVER数据库的时候,经常需要两个数据库之间进行同步工作。

同步可以由SQL SERVER通过作业来自动完成,如下逻辑代码供参考:

--	INSERT INTO [172.29.11.212].FlexSFS.dbo.tbWorkOrder 
--	select * from tbWorkOrder where DateCreated>@THEDATE AND CodeWorkorder NOT IN 
--	(SELECT CodeWorkorder FROM [172.29.11.212].FlexSFS.dbo.tbWorkOrder WHERE DateCreated>@THEDATE)	
	
	--INSERT INTO tbPackage 
	--select * from [172.29.11.212].FlexSFS.dbo.tbPackage where DateCreated>@THEDATE AND CodePackage NOT IN 
	--(SELECT CodePackage FROM tbPackage WHERE DateCreated>@THEDATE)	
	
--	INSERT INTO [172.29.11.212].FlexSFS.dbo.tbPackage 
--	select * from tbPackage where DateCreated>@THEDATE AND CodePackage NOT IN 
--	(SELECT CodePackage FROM [172.29.11.212].FlexSFS.dbo.tbPackage WHERE DateCreated>@THEDATE)		
	
	--INSERT INTO tbHandOver 
	--select * from [172.29.11.212].FlexSFS.dbo.tbHandOver where DateCreated>@THEDATE AND CodeHandOver NOT IN 
	--(SELECT CodeHandOver FROM tbHandOver WHERE DateCreated>@THEDATE)	

--	INSERT INTO [172.29.11.212].FlexSFS.dbo.tbHandOver 
--	select * from tbHandOver where DateCreated>@THEDATE AND CodeHandOver NOT IN 
--	(SELECT CodeHandOver FROM [172.29.11.212].FlexSFS.dbo.tbHandOver WHERE DateCreated>@THEDATE)
	
	--INSERT INTO tbProduct 
	--select * from [172.29.11.212].FlexSFS.dbo.tbProduct where TimeCreated>@THEDATE AND CodeProduct NOT IN 
	--(SELECT CodeProduct FROM tbProduct WHERE TimeCreated>@THEDATE)	

--	INSERT INTO [172.29.11.212].FlexSFS.dbo.tbProduct 
--	select * from tbProduct where TimeCreated>@THEDATE AND CodeProduct NOT IN 
--	(SELECT CodeProduct FROM [172.29.11.212].FlexSFS.dbo.tbProduct WHERE TimeCreated>@THEDATE)	

 

同步MSSQL数据



转载请注明:CWAPI » 特定条件下,同步两个SQL Server数据库数据