I need to do a join across two different database servers (IPs 10.0.0.50 and 10.0.0.51). What's the best way?
我需要跨两个不同的数据库服务器执行连接(IPs 10.0.0.50和10.0.0.51)。最好的方法是什么?
4 个解决方案
#1
13
You need to use sp_linkedserver to create a linked server.
您需要使用sp_linkedserver来创建一个链接服务器。
sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ]
[ , [ @provider= ] 'provider_name' ]
[ , [ @datasrc= ] 'data_source' ]
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string' ]
[ , [ @catalog= ] 'catalog' ]
More information available on MSDN.
更多关于MSDN的信息。
#2
17
The solution I found:
我找到了解决方案:
1) Run a stored proc
1)运行存储的proc
exec sp_addlinkedserver @server='10.0.0.51'
2) Verify that the servers were linked (lists linked servers)
2)验证服务器是否链接(列出链接的服务器)
exec sp_linkedservers
3) Run the query using the format
3)使用该格式运行查询
[10.0.0.51].DatabaseName.dbo.TableName
#3
9
I know that the answers above are good, but wanted to share some details that I hope others will find helpful. Worth to mention is the user access part, which I think people will need help with.
我知道上面的答案很好,但是我想分享一些我希望别人会觉得有用的细节。值得一提的是用户访问部分,我认为人们需要帮助。
set up the link:
设置链接:
exec sp_addlinkedserver @server='10.10.0.10\MyDS';
exec sp_addlinkedserver @server =“10.10.0.10 \ MyDS”;
set up the access for remote user, example below:
设置远程用户的访问权限,示例如下:
exec sp_addlinkedsrvlogin '10.10.0.10\MyDS', 'false', null, 'adm', 'pwd';
exec sp_addlinkedsrvlogin '10.10.0.10\MyDS', 'false', null, 'adm', 'pwd';
see the linked servers and user logins:
查看链接的服务器和用户登录:
exec sp_linkedservers;
exec sp_linkedservers;
select * from sys.servers;
从sys.servers select *;
select * from sys.linked_logins;
从sys.linked_logins select *;
run the remote query:
运行远程查询:
select * from [10.10.0.10\MyDS].MyDB.dbo.TestTable;
select * from[10.10.0.10 \ MyDS].MyDB.dbo.TestTable;
drop the linked server and the created login users (adm/pwd)
删除链接服务器和创建的登录用户(adm/pwd)
exec sp_dropserver '10.10.0.10\MyDS', 'droplogins'; -- drops server and logins
exec sp_dropserver‘10.10.0.10 \ MyDS’,‘droplogins’;——删除服务器和登录
resources:
资源:
sp_addlinkedserver
sp_dropserver
sp_addlinkedsrvlogin
sp_droplinkedsrvlogin
#4
5
You can, as mentioned, use sp_addlinkedserver. However, you may also do this via Enterprise Manager (2000) or SQL Server Management Studio (2005). Under the "Security" node, there is a "Linked Servers" node, which you can use to add and configure Linked Servers. You can specify security settings, impersonation, etc.
如前所述,您可以使用sp_addlinkedserver。但是,您也可以通过Enterprise Manager(2000)或SQL Server Management Studio(2005)实现这一点。在“Security”节点下,有一个“链接服务器”节点,您可以使用该节点添加和配置链接服务器。您可以指定安全设置、模拟等。
See these for SQL Server 2000:
参见SQL Server 2000:
配置连接服务器
Establishing Security For Linked Servers
建立连接服务器的安全性
Configuring OLEDB Providers for Distributed Queries
为分布式查询配置OLEDB提供程序
See these for SQL Server 2005:
参见SQL Server 2005:
连接服务器
连接服务器的安全
Configuring Linked Servers for Delegation
为委托配置链接服务器
Configuring OLEDB Providers for Distributed Queries
为分布式查询配置OLEDB提供程序
#1
13
You need to use sp_linkedserver to create a linked server.
您需要使用sp_linkedserver来创建一个链接服务器。
sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ]
[ , [ @provider= ] 'provider_name' ]
[ , [ @datasrc= ] 'data_source' ]
[ , [ @location= ] 'location' ]
[ , [ @provstr= ] 'provider_string' ]
[ , [ @catalog= ] 'catalog' ]
More information available on MSDN.
更多关于MSDN的信息。
#2
17
The solution I found:
我找到了解决方案:
1) Run a stored proc
1)运行存储的proc
exec sp_addlinkedserver @server='10.0.0.51'
2) Verify that the servers were linked (lists linked servers)
2)验证服务器是否链接(列出链接的服务器)
exec sp_linkedservers
3) Run the query using the format
3)使用该格式运行查询
[10.0.0.51].DatabaseName.dbo.TableName
#3
9
I know that the answers above are good, but wanted to share some details that I hope others will find helpful. Worth to mention is the user access part, which I think people will need help with.
我知道上面的答案很好,但是我想分享一些我希望别人会觉得有用的细节。值得一提的是用户访问部分,我认为人们需要帮助。
set up the link:
设置链接:
exec sp_addlinkedserver @server='10.10.0.10\MyDS';
exec sp_addlinkedserver @server =“10.10.0.10 \ MyDS”;
set up the access for remote user, example below:
设置远程用户的访问权限,示例如下:
exec sp_addlinkedsrvlogin '10.10.0.10\MyDS', 'false', null, 'adm', 'pwd';
exec sp_addlinkedsrvlogin '10.10.0.10\MyDS', 'false', null, 'adm', 'pwd';
see the linked servers and user logins:
查看链接的服务器和用户登录:
exec sp_linkedservers;
exec sp_linkedservers;
select * from sys.servers;
从sys.servers select *;
select * from sys.linked_logins;
从sys.linked_logins select *;
run the remote query:
运行远程查询:
select * from [10.10.0.10\MyDS].MyDB.dbo.TestTable;
select * from[10.10.0.10 \ MyDS].MyDB.dbo.TestTable;
drop the linked server and the created login users (adm/pwd)
删除链接服务器和创建的登录用户(adm/pwd)
exec sp_dropserver '10.10.0.10\MyDS', 'droplogins'; -- drops server and logins
exec sp_dropserver‘10.10.0.10 \ MyDS’,‘droplogins’;——删除服务器和登录
resources:
资源:
sp_addlinkedserver
sp_dropserver
sp_addlinkedsrvlogin
sp_droplinkedsrvlogin
#4
5
You can, as mentioned, use sp_addlinkedserver. However, you may also do this via Enterprise Manager (2000) or SQL Server Management Studio (2005). Under the "Security" node, there is a "Linked Servers" node, which you can use to add and configure Linked Servers. You can specify security settings, impersonation, etc.
如前所述,您可以使用sp_addlinkedserver。但是,您也可以通过Enterprise Manager(2000)或SQL Server Management Studio(2005)实现这一点。在“Security”节点下,有一个“链接服务器”节点,您可以使用该节点添加和配置链接服务器。您可以指定安全设置、模拟等。
See these for SQL Server 2000:
参见SQL Server 2000:
配置连接服务器
Establishing Security For Linked Servers
建立连接服务器的安全性
Configuring OLEDB Providers for Distributed Queries
为分布式查询配置OLEDB提供程序
See these for SQL Server 2005:
参见SQL Server 2005:
连接服务器
连接服务器的安全
Configuring Linked Servers for Delegation
为委托配置链接服务器
Configuring OLEDB Providers for Distributed Queries
为分布式查询配置OLEDB提供程序