Selecting data from two different servers in SQL Server

Don Of Qau picture Don Of Qau · Jul 17, 2009 · Viewed 755.1k times · Source

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

Answer

Eric picture Eric · Jul 17, 2009

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:

Server Objects-->Linked Servers

or you can use 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.