How do I link two SQL servers so I can run queries between them?

×
  • Link the servers - sp_addlinkedserver [{Remote Server Name}]
  • Set login information (only required if your connection isn't trusted) - 

    sp_addlinkedsrvlogin '{Remote Server Name}', 'false', NULL, '{User Name}', '{Password}'


Now you can run a query against the remote server with the following syntax:

select top 10 * from [{Remote Server Name}].[{Database Name}].{Owner}.[{Table Name}]

Example querying SQL Server MySQLServer1 with a database name of Data, owner of dbo (the default), and a table name of Customers:

select top 10 * from [MySQLServer1].[Data].dbo.[Customers]