/*
在本机通过SQL远程操作数据库@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
declare @ServerName sysname
declare @UserName sysname
declare @Password sysname
--初始化连接信息
set @ServerName='192.168.223.90\sql2008'
set @UserName='sa'
set @Password='Wj1234567892'
--打开连接
IF not EXISTS (select srvid from master.dbo.sysservers where srvname = @ServerName )
EXEC sp_addlinkedserver @ServerName
EXEC sp_addlinkedsrvlogin @ServerName ,'false', null, @UserName, @Password
--SQL操作
--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