Link server will be useful to establish the Link between to servers and retrieve the data.
creating the link server can be done in two methods.
1. Use
sp_addlinkserver
2. Open Sql server Management Studio
go to Server Objects (see below)
Give the ServerName, Product Name, DataSource (see below)
Go to Security settings and enter the credentials to use the Database(see below).
Then click on OK this will create the Linked server.
Using the linked server
we can use the linked server using OPENQUERY:
SELECT * INTO dbo.testlinkserver
FROM OPENQUERY(LOCALSERVER, 'SELECT * FROM dbo.testlinkserver' )
In the above Query LOCALSERVER is the Linked server Name
testlinkserver is Table Name.
Result of the above Query is it will create the table called testlinkserver and dump the Data from Data Source which you are linked to.