两个MSSQL导入的语句问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 07:23:12
我有两台服务器192.168.0.1和192.168.0.2
两台服务器上的数据库名、表结构都一模一样。
现在我的需求是每天凌晨定时从192.168.0.1的数据库A中的a1表向192.168.0.2的数据库A中的a1表进行差异导入数据。
请问导入的SQL语句怎么写,至于定时我会使用作业来完成。所以定时的语句不需要,只需要导入的语句。谢谢了。

看看这个语句可能对你有帮助
if object_id('tempdb..#tb') is not null
begin
drop table #tb
end

select htm.id,htm.[name],htm.hhh,html.id as xid into #tb from htm left outer join html on htm.id=html.id
update html set html.html=b.[name],html.hhhh=b.hhh from
(select * from #tb a where a.xid is not null) b
where html.id=b.id
insert into html(id,html,hhhh) select b.id,b.[name],b.hhh from (select * from #tb a where a.xid is null) b
delete from htm