/ *
In the operation of the machine by remote SQL database @@@@@@@@@@@@@@@@@@@@@@@@@@
* /
DECLARE @ servername Sysname
DECLARE @UserName Sysname
DECLARE the @Password Sysname
- initialization connection information
SET ServerName = @ '192.168.223.90 \ SQL2008'
SET @ UserName = 'SA'
SET @ Password = 'Wj1234567892'
- open a connection
IF not EXISTS (select srvid from master.dbo.sysservers where srvname = @ ServerName)
EXEC the sp_addlinkedserver @ servername
EXEC the sp_addlinkedsrvlogin @ servername, 'to false', null, @UserName, the @Password
- SQL operation
--Exec ('select * from [' + @ServerName + '].Xlink.adm.Message ')--adm.Message
--Exec ('select * from ShipmentMethodFCL_temp')
--Exec ('Insert into ['+ @ServerName+'].Xlink.dbo.ShipmentMethodFCL_temp select * from ShipmentMethodFCL_temp ')
-- Exec ('Insert into ['+ @ServerName+'].Xlink.dbo.ShipmentMethodLCL_temp select * from ShipmentMethodLCL_temp ')
--关闭连接
EXEC sp_droplinkedsrvlogin @ServerName,@UserName
EXEC sp_droplinkedsrvlogin @ServerName,null
EXEC sp_dropserver @ServerName
Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2011/11/09/2243455.html