Next step of programming

Just another WordPress.com weblog

Posts Tagged ‘SP_ADDLINKEDSRVLOGIN

Linking another SQL Server instance Part 1

with one comment

There can be case or a requirement to attach the another sql server to your existing sql server instance so that you can work on the both server at same time. Get data from both the server from one query as a single result, managing all server from one location or for various work you can utilise it.

Linking another server

for that we have to use sp_addlinkedserver. one of the example

EXEC sp_addlinkedserver   
@server='inventory', 
@srvproduct='',
   @provider='SQLNCLI', 
@datasrc='server\mssql2005'

for more information on this visit sp_addlinkedserver (Transact-SQL) – MSDN

Here we added the server\mssql2005 as the inventory server as linked server now we have to add the login information for that we have to use

EXEC sp_addlinkedsrvlogin 'inventory', 
'false', 'mydomain\user2', 
'sa', 'sapassword

To get more information on this checkout sp_addlinkedsrvlogin (Transact-SQL) – MSDN

Now that server is linked and ready to be user. we can use the following query to get the data from the server

SELECT * FROM [inventory].master.dbo.sysobjects

Written by A.Sethi

September 13, 2008 at 6:56 am