Sql自动更新不同IP的数据库数据。(link Server)

 

if not exists(select    *    from    master.dbo.sysservers    where    srvname='srv_lnk6' and datasource='19.127.57.227')  
begin   
     if exists(select    *    from    master.dbo.sysservers    where    srvname='srv_lnk6')  
      begin--IP的改变时删除注名
           exec sp_droplinkedsrvlogin 'srv_lnk6',null
           exec sp_dropserver    'srv_lnk6'
      end
          exec sp_addlinkedserver    'srv_lnk6','','SQLOLEDB','19.127.57.227'
end
      exec sp_addlinkedsrvlogin 'srv_lnk6','false',null,'sa','123456'
exec('insert into srv_lnk6.trade.dbo.news(type,zllb,zt,zt_color,zt_b,nr)select ''3'',''2'',file_title,''#333333'',''1'',file_content from recfile where id={0}')

 

来自:http://hi.baidu.com/lintan7878/blog/item/5431a944c1babf4d510ffe22.html

你可能感兴趣的:(server)