首页 > 代码库 > Select In SQL Server-Cross Instance in same domain and different domain

Select In SQL Server-Cross Instance in same domain and different domain

Same Domain:

Exec sp_addlinkedserver ‘PC087‘:Add Remote Server

Exec sp_dropserver ‘InstcanceName‘:Delete Remote Server

sp_helpserver check already registed server at current

存储过程名/视图名 作用 举例
sp_addlinkedserver 注册远程数据库实例 exec sp_addlinkedserver ‘InstanceName’
sp_dropserver 删除远程数据库实例 exec sp_dropserver ‘InstanceName’
sp_addlinkedsrvlogin 注册远程实例登陆访问帐户 exec sp_addlinkedsrvlogin ‘InstanceName’, null
sp_droplinkedsrvlogin 删除远程实例登陆访问帐户 EXEC sp_droplinkedsrvlogin ‘InstanceName‘,‘UserName‘
sp_helpserver 当前实例已注册的可访问的实例(即查看使用sp_addlinkedserver已注册过的实例) sp_helpserver
sys.sysservers 功能同sp_helpserver select * from sys.sysservers
sys.linked_logins 查看已注册的登陆访问帐户(即查看使用sp_addlinkedsrvlogin已注册过的帐户) select * from sys.linked_logins
sys.remote_logins 查看已注册的远端访问帐户 select * from sys.remote_logins

 

Different Domain:

Use [Tracks]

UPDATE [Tracks].[dbo].Shipment  SET [Tracks].[dbo].Shipment.IsPublic=tdss.[IsPublic] 

FROM

(select * from opendatasource(‘SQLOLEDB‘ , ‘Data Source=IP Address; User ID=sa;Password=password‘).[LoadTestManagerUI].[dbo].[TripDetailForShipmentSearch]) 

as tdss  

inner join [Tracks].[dbo].Shipment  s ON tdss.ShipmentId=s.ShipmentId 

Select In SQL Server-Cross Instance in same domain and different domain