Use of Linked Server IN Sql Server

For Fetching data from database situated at another server, we have to create Linked Server.

Command for creating Linked Server and linked server login:

Use master

EXEC
sp_addlinkedserver
@server = 'AnyServerName',
@srvproduct
= '',
@provider
= 'MSDASQL',
@provstr
= 'DRIVER={SQL Server};SERVER=.;UID=myself;PWD=password;'

EXEC sp_addlinkedsrvlogin 'AnyServerName', 'false', NULL, 'myself', 'password'

U can see the server name by using this command

SELECT
* FROM sys.servers

Now you have created LinkedSerever named 'AnyServerName'

by using this LinkedServerName you can fetch data from another database situated at another location


SELECT
TOP 20 * from AnyServerName.DatabaseName.dbo.TableName

Ebook Download
View all
Learn
View all