[英]How can I select data in the same query from two different servers and databases from SQL Server Management Studio?
如何从两个不同服务器(一个DB2服务器和另一个SQL Server)上的两个不同数据库中选择同一查询中的数据?
On your sql server, set up a linked server to the db2 database. 在SQL Server上,将链接服务器设置为db2数据库。
Then write your query on sql server. 然后在sql server上编写查询。 I suggest that you use openquery for the db2 stuff. 我建议你使用openquery作为db2的东西。 If you have to combine the data, populate a sql server temp table with the openquery results and work from there. 如果必须组合数据,请使用openquery结果填充sql server临时表并从那里开始工作。
The reason I suggest this is performance. 我建议这是性能的原因。 I have found that if you use this syntax 我发现如果你使用这种语法
select somefields
from server.database.owner.table
where whatever
sql server will bring back the entire table from the linked server and apply the where clause afterwards. SQL Server将从链接服务器返回整个表,然后应用where子句。
You can set up a linked server http://support.microsoft.com/kb/222937 您可以设置链接服务器http://support.microsoft.com/kb/222937
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.