首页 > 解决方案 > 如何通过注册服务器/服务器组查询多个服务器?

问题描述

我们使用某个医疗保健信息系统,将我们的医院分成多个服务器,我的公司正在发展壮大,这导致需要在 5 个以上的服务器数据库中运行一个简单的查询。

我最近了解了如何设置注册服务器本地组并进行设置。然后在尝试查询时碰壁。

问题是我们的数据库是基于环境的前缀,所以我需要一种方法来运行一个具有两个不同数据库表名的查询。

例子:

现场fdb.dbo.BlahBlah 中选择 *

测试fdb.dbo.BlahBlah 中选择 *

希望当我查询前 4 个字符使用通配符时有某种方法。

标签: sqlsql-server

解决方案


You can do this but you'll have to use linked servers instead. Multi-server queries in SSMS won't work for you in this situation.

Given your constraints, I'd do this:

  1. On one server, create a linked server to the other servers.
  2. Create a view that queries each of the servers and uses UNION ALL to combine the results.
  3. Just query that view from one server.

推荐阅读