假如有两台sql server,需要连接另外一台进行 查询
另外一台叫10.1.1.5
查询语句是:select top 10 * from [10.1.1.5].[DB名].[dbo].[表名]
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
image.png
image.png
image.png
image.png
本文链接:https://blog.runxinyun.com/post/217.html 转载需授权!
留言0