数据库跨服务器更新表内容

跨服务器连接参考链接:
 
 
 
 
//创建远程链接
exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', 'ren' //ren 为服务器地址
 
exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, 'sa', 'sa01234'
 
 
启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
 
更新语句
update ren
set ren.number= cui.number
from openrowset( 'SQLOLEDB ', 'ren'; 'sa'; 'sa01234',jp.dbo.ren) as a //ren为表名
inner join cui
on a.name =cui.id
 
 
关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
 
//断开链接
exec sp_dropserver 'ITSV ', 'droplogins '
posted @ 2020-05-26 17:03  东风神Eurus  阅读(208)  评论(0编辑  收藏  举报