/****** 对象: LinkedServer [202.99.213.226] 脚本日期: 06/26/ 21:34:35 ******/
EXEC master.dbo.sp_addlinkedserver @server = N'NFDRP', @srvproduct=N'SQL Server'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'202.99.213.226',@useself=N'False',@locallogin=NULL,@rmtuser=N'sa',@rmtpassword='########'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'collation name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'202.99.213.226', @optname=N'use remote collation', @optvalue=N'false'
上面是建立链接服务器的代码,下面是删除服务器的代码
---------------------------
/****** 对象: LinkedServer [202.99.213.226] 脚本日期: 06/26/ 21:50:58 ******/
IF EXISTS (SELECT srvname FROM master.dbo.sysservers srv WHERE srvid != 0 AND srvname = N'202.99.213.226')EXEC master.dbo.sp_dropserver @server=N'202.99.213.226', @droplogins='droplogins'
-----------------------------------
查询示例
select * from [202.99.213.226].nafine1129.dbo.biarea
---------------------
SELECT top 10 *
FROM
OPENDATASOURCE('SQLOLEDB','Data Source=202.99.213.226;User ID=sa;Password=nafineyxb').nafine1129.dbo.biarea
---------这是纯命令方式。关于这方面的内容还是多看微软的帮助,微软帮助确实做的好。