从 SQL Server 中的两个不同服务器中选择数据 [英] Selecting data from two different servers in SQL Server

查看:25
本文介绍了从 SQL Server 中的两个不同服务器中选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 SQL Server 中两个不同服务器上的两个不同数据库中选择同一查询中的数据?

How can I select data in the same query from two different databases that are on two different servers in SQL Server?

推荐答案

您正在寻找的是链接服务器.您可以从对象资源管理器树中的以下位置在 SSMS 中找到它们:

What you are looking for are Linked Servers. You can get to them in SSMS from the following location in the tree of the Object Explorer:

服务器对象-->链接服务器

或者您可以使用 sp_addlinkedserver.

您只需设置一个.一旦你有了它,你就可以像这样调用另一个服务器上的表:

You only have to set up one. Once you have that, you can call a table on the other server like so:

select
    *
from
    LocalTable,
    [OtherServerName].[OtherDB].[dbo].[OtherTable]

请注意,所有者并不总是 dbo,因此请确保将其替换为您使用的任何架构.

Note that the owner isn't always dbo, so make sure to replace it with whatever schema you use.

这篇关于从 SQL Server 中的两个不同服务器中选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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