Thursday, April 21, 2022

SQL Server : querying from another server


You needed to link the server.

To check if already linked:

select * from sys.servers


If not, use:

EXEC sp_addlinkedserver @server='servername\instance'

EXEC sp_addlinkedsrvlogin 'servername\instance', 'false', NULL, 'userLoginname', 'pa$$w0rd'


Now you can use queries like:


   select * from [servername\instance].DatabaseName.dbo.Tablename



     select * from [servername\instance].msdb.sys.sysobjects 


No comments: