Advertisement
Beginner SQL Server, Linked Servers

How do you write a query that retrieves data from a table on a linked server?

Short answer

You reference the remote table using a four part naming convention consisting of the linked server name, the remote database name, the schema, and the table name, letting you query that remote table directly within your SQL statement just as you would query a local table.

Save SQL Server mock interview
Advertisement
AModel answer
You reference the remote table using a four part naming convention consisting of the linked server name, the remote database name, the schema, and the table name, letting you query that remote table directly within your SQL statement just as you would query a local table.
SELECT * FROM RemoteServer.SalesDB.dbo.Customers;
Real-world example
A finance report combines local order data with customer information stored on a separate linked server, using the four part naming convention to seamlessly query both sources in a single statement.
Likely follow-ups
  • What does each part of the four part naming convention represent?
  • Can you join a local table with a table on a linked server in the same query?
Related topics