如何在一个SQL查询中联接来自两个不同SQL Server实例的表 [英] How do you join tables from two different SQL Server instances in one SQL query

查看:547
本文介绍了如何在一个SQL查询中联接来自两个不同SQL Server实例的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
从SQL Server中的两个不同服务器中选择数据

Possible Duplicate:
Selecting data from two different servers in SQL Server

如何在一个查询中联接位于两个不同SQL Server实例的两个表?

How can I join two tables, which are located two different SQL Server instances, in one query?

推荐答案

我能想到的最好方法是通过 sp_addlinkedserver .您需要确保使用任何帐户添加链接(通过 sp_addlinkedsrvlogin )有权访问您要加入的表,但是一旦链接建立,您就可以按名称调用服务器,即:

The best way I can think of to accomplish this is via sp_addlinkedserver. You need to make sure that whatever account you use to add the link (via sp_addlinkedsrvlogin) has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:

SELECT *
FROM server1table
    INNER JOIN server2.database.dbo.server2table ON .....

这篇关于如何在一个SQL查询中联接来自两个不同SQL Server实例的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆