sql server创建固定的链路服务器
假如有两台sql server,需要连接另外一台进行 查询
另外一台叫10.1.1.5
查询语句是:select top 10 * from [10.1.1.5].[DB名].[dbo].[表名]
[10.1.1.5]的创建办法
EXEC master.dbo.sp_addlinkedserver @server = N'10.1.1.5', @srvproduct=N'SQL Server'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'10.1.1.5',@useself=N'False',@locallogin=NULL,@rmtuser=N'sa',@rmtpassword='数据库密码'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'collation name', @optvalue=NULL
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'use remote collation', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'10.1.1.5', @optname=N'remote proc transaction promotion', @optvalue=N'false'
GO
也可以手动创建:
最后可进行测试
如果是连接到其他非sql server数据源也是可行的