EXEC sp_addlinkedserver
@server=N'remoteserver',
@srvproduct=N'',
@provider=N'SQLNCLI',
@datasrc=N'ip,port'
go
exec sp_addlinkedsrvlogin
N'remotedb',
N'false',
null,
N'sqlid',
N'sqlpwd'
go
begin
BEGIN TRY
insert into FinancialCalendarData
select remotedb.*,'' as jin10
from [remoteserver].[dbname].dbo.[tablename] remotedb
left loop join tablename localdb
on remotedb.[Date] = localdb.[Date] and remotedb.[Time] = localdb.[Time]
and remotedb.CountryName = localdb.CountryName and remotedb.Content = localdb.Content
and remotedb.DataTypeName = localdb.DataTypeName and remotedb.Source = localdb.Source
where localdb.[Date] is null
END TRY
BEGIN CATCH
PRINT 'Error Message: ' + ERROR_MESSAGE();
END CATCH
end
go
exec sp_dropserver N'remoteserver',N'droplogins';
go
远程同步数据库
最新推荐文章于 2022-07-18 20:05:45 发布