sql2008R2新建链接服务器。
1:用sql新建链接服务器对象:
/****** Object: LinkedServer [pad] Script Date: 10/23/2018 15:47:45 ******/ EXEC master.dbo.sp_addlinkedserver @server = N'AXMesDB', @srvproduct=N' ', @provider=N'SQLNCLI', @datasrc=N'172.22.160.39' /* For security reasons the linked server remote logins password is changed with ######## */ EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'AXMesDB',@useself=N'False',@locallogin=NULL,@rmtuser=N'数据库登录账号',@rmtpassword='密码' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'collation compatible', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'data access', @optvalue=N'true' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'dist', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'pub', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'rpc', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'rpc out', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'sub', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'connect timeout', @optvalue=N'0' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'collation name', @optvalue=null GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'lazy schema validation', @optvalue=N'false' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'query timeout', @optvalue=N'0' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'use remote collation', @optvalue=N'true' GO EXEC master.dbo.sp_serveroption @server=N'AXMesDB', @optname=N'remote proc transaction promotion', @optvalue=N'true' GO
2:执行完成后刷新sql后会出现如下图的红框链接对象:
3:对远程服务器sql查询就可以如下: