Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

sql - 从SQL Server中的两个不同服务器中选择数据(Selecting data from two different servers in SQL Server)

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

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

(您可以从“对象资源管理器”树中以下位置的SSMS中找到它们:)

Server Objects-->Linked Servers

or you can use sp_addlinkedserver .

(或者您可以使用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]

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...