Add Linked Server

Purpose of Linked Server :

The system stored procedure SP_AddLinkedServer is used in order to link a server from the server in which you are executing the command. In order to connect to a remote SQL Server.


For example :

Suppuse you have Sql server Name With :  Node15 Database Name : Users

Now you have other Sql server Name  : Node17 Database Name : Employee

Now you want to show some reocrd of employee in your Application which is attached with Node15. So at that time Linked server is Useful.

Here the step to execute and you will get the records from Other database server.

Step 1 :
 
       EXEC sp_addlinkedserver  @server = 'YourSqlServerName'

       Here @ServerName : Give Sql Server Name in which you want to connect

Step 2 :

    EXEC sp_addlinkedsrvlogin @rmtsrvname='YourSqlServerName', @Useself='False',@locallogin=NULL,
    @rmtuser='UserName', @rmtpassword='Password'

   @rmtuser : Give User name of the database which you want to connect
   @rmtpassword : Give Password of the database which you want to connect

Step 3 :


   Select * from [YourDatabaseName].[DatabaseName].dbo.TableName

   Now By this query you can fetch the record.

Step 4 :

   To remove the link with server which you connected.

   EXEC Sp_DropServer @Server= 'YourSqlServerName',@droplogins='droplogins'


Notice : If you want to Insert ,Update Or delete on the same way you can do with linked server.

---------------------
Thanks & Regards
Gaurang Upadhyay
Sr. Developer