跨多个 SQL 服务器的 SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25406989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Query across multiple SQL servers
提问by Andy T
I have 2 SQL servers. I need a SQL query that can join 2 tables that are in two different server.
我有 2 个 SQL 服务器。我需要一个可以连接两个不同服务器中的 2 个表的 SQL 查询。
Like
喜欢
SELECT *
FROM Server1.Db1.dbo.table1 A
INNER JOIN Server2.Db1.dbo.table2 B ON A.Id = B.Id
and I do not have the server names, instead I am using IP address of the servers. Do I need to enable these SQL servers as linked server to allow such cross server queries?
我没有服务器名称,而是使用服务器的 IP 地址。我是否需要启用这些 SQL 服务器作为链接服务器以允许此类跨服务器查询?
回答by Nadeem_MK
You can proceed with Linked Servers using sp_addlinkedserver
.
Once done, you can query your data as you mentioned;
您可以继续使用链接服务器sp_addlinkedserver
。完成后,您可以按照您提到的方式查询您的数据;
SELECT *
FROM [Db1].[dbo].table1 A
INNER JOIN [Server2].[Db1].[dbo].table2 B
ON A.Id = B.Id
回答by Hlin
Yes, add as linker server is one option. You also can join the remote table by use [ip address].dbname.dbo.table name s well.
是的,添加为链接器服务器是一种选择。您也可以使用 [ip address].dbname.dbo.table name s 加入远程表。