Sql – Selecting data from two different servers in SQL Server

sqlsql server

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

Best Answer

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:


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