Linked Server 可以实现分布式查询,下图是一个基本的Linked Server配制图:
我们可以使用T-sql script来更加简洁的创建Linked Server:
EXEC master.dbo.sp_addlinkedserver @server = N'SERVER',
@srvproduct = 'SERVER',
@provider = 'SQLNCLI10',
@datasrc = 'SERVER',
@location = '',
@provstr = '',
@catalog = ''
GO
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'SERVER',
@locallogin = N'admin',
@useself = 'false',
--You can only login with a Windows login, if you are already logged into Windows with that login.
--Thus @rmtuser must be an SQL login.
@rmtuser = 'sa',
@rmtpassword='xxxxxxxx'
GO
Note: sp_addlinkedsrvlogin 的@rmtuser 通常需要指定一个SQL SERVER Login account.
建立好后,要执行一个查询应该由四个部分组成: linked_server_name.catalog.schema.object_name
更多可参考:
Linking Servers
http://msdn.microsoft.com/en-us/library/ms188279.aspx
Distributed Queries
http://msdn.microsoft.com/en-us/library/ms188721.aspx
Linked Server Properties (Security Page)
http://msdn.microsoft.com/en-us/library/ms188477.aspx
希望这篇Post对您有帮助.