在SQL Server上查询多个数据库

时间:2021-02-12 01:34:16

is it possible to create a view that selects from

是否可以创建一个选择的视图

  1. multiple tables
  2. in different databases
  3. 在不同的数据库

  4. on different servers
  5. 在不同的服务器上

  6. using different login credentials
  7. 使用不同的登录凭据

Can someone point to any online examples.

有人可以指向任何在线示例。

Or is there any way I can do it using Linq if I cant create a view

或者,如果我无法创建视图,我有什么方法可以使用Linq

2 个解决方案

#1


Yes, you'll want to use something called a linked server:

是的,你会想要使用一个叫做链接服务器的东西:

http://www.databasejournal.com/features/mssql/article.php/3085211/Linked-Servers-on-MS-SQL-Part-1.htm

You'll need to be database admin in order to set it up, though.

但是,您需要成为数据库管理员才能进行设置。

If you can't create a view, you will have to perform two separate LINQ to SQL queries using two separate DataContexts, and then call .ToList() or. ToArray() on the results, and then join them in a third LINQ query. This will work fine as long as you can limit each query to have a relatively small number of elements (under, say, 1000 or so from each LINQ query).

如果无法创建视图,则必须使用两个单独的DataContexts执行两个单独的LINQ to SQL查询,然后调用.ToList()或。 ToArray()关于结果,然后将它们连接到第三个LINQ查询中。只要您可以将每个查询限制为具有相对较少的元素(在每个LINQ查询下,例如1000左右),这将正常工作。

#2


This type of implemenation/technique is also used in Federated Database Servers to distribute the processing load of large scale SQL Server database systems.

这种类型的实现/技术也用于联合数据库服务器,以分发大规模SQL Server数据库系统的处理负载。

See the following Books Online reference for more details:

有关详细信息,请参阅以下联机丛书参考:

http://msdn.microsoft.com/en-us/library/ms190381.aspx

As per the prior posters instruction regarding setting up Linked Servers, you will subsequently need to create Partitioned Views, more details can be found in Books Online under there sub heading 'Partitioned Views':

根据之前关于设置链接服务器的海报说明,您随后需要创建分区视图,更多详细信息可以在联机丛书中的子标题“分区视图”下找到:

http://msdn.microsoft.com/en-us/library/ms187956.aspx

#1


Yes, you'll want to use something called a linked server:

是的,你会想要使用一个叫做链接服务器的东西:

http://www.databasejournal.com/features/mssql/article.php/3085211/Linked-Servers-on-MS-SQL-Part-1.htm

You'll need to be database admin in order to set it up, though.

但是,您需要成为数据库管理员才能进行设置。

If you can't create a view, you will have to perform two separate LINQ to SQL queries using two separate DataContexts, and then call .ToList() or. ToArray() on the results, and then join them in a third LINQ query. This will work fine as long as you can limit each query to have a relatively small number of elements (under, say, 1000 or so from each LINQ query).

如果无法创建视图,则必须使用两个单独的DataContexts执行两个单独的LINQ to SQL查询,然后调用.ToList()或。 ToArray()关于结果,然后将它们连接到第三个LINQ查询中。只要您可以将每个查询限制为具有相对较少的元素(在每个LINQ查询下,例如1000左右),这将正常工作。

#2


This type of implemenation/technique is also used in Federated Database Servers to distribute the processing load of large scale SQL Server database systems.

这种类型的实现/技术也用于联合数据库服务器,以分发大规模SQL Server数据库系统的处理负载。

See the following Books Online reference for more details:

有关详细信息,请参阅以下联机丛书参考:

http://msdn.microsoft.com/en-us/library/ms190381.aspx

As per the prior posters instruction regarding setting up Linked Servers, you will subsequently need to create Partitioned Views, more details can be found in Books Online under there sub heading 'Partitioned Views':

根据之前关于设置链接服务器的海报说明,您随后需要创建分区视图,更多详细信息可以在联机丛书中的子标题“分区视图”下找到:

http://msdn.microsoft.com/en-us/library/ms187956.aspx