SharonsFuzzyArian











{January 30, 2010}   SQL Linked Server

A linked server configuration enables SQL Server to execute commands against OLE DB data sources on remote servers. Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements.

Linked servers offer the following advantages:

1. Remote server access.
2. The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
3. The ability to address diverse data sources similarly.

We were working on various servers and there was a case where we had to compare data from 2 different Servers. I created a Temp table to store the needed values in one Server and in other Server was the actual table, that needs to be compared with. So i used the Linked Server concept and it gave the exact results as needed.

Try this:

sp_addlinkedserver @server=’linkedserver1′,@srvproduct=”,@provider=’SQLOLEDB’,@datasrc=’ServerName’

sp_addlinkedsrvlogin ‘linkedserver1′,’false’,null,’username’,’password’

SELECT  * FROM linkedserver1.DBName.TableName

In this way we can perform how many ever SQL Operations with as many tables needed.

It really made the job very simple as it was a very compelling reasons in a short time. 🙂

Life thus made easy 😉



abhijit says:

i have added one linked server as

sp_addlinkedserver @server=’erpserver\server′, @srvproduct=”,@provider=’SQLOLEDB’,@datasrc=’builtup’

sp_addlinkedsrvlogin ‘erpserver\server′,’false’,null,’sa’,’saptech@123’

SELECT * FROM erpserver\server.builtup.users

but getting following error –

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘’’.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ‘saptech@123’

SELECT * FROM erpserver\server.builtup.users
‘.

pls help me on this



abhijit says:

i have added one linked server as

sp_addlinkedserver @server=’erpserver\server′, @srvproduct=”,@provider=’SQLOLEDB’,@datasrc=’builtup’

sp_addlinkedsrvlogin ‘erpserver\server′,’false’,null,’sa’,’saptech@123’

SELECT * FROM erpserver\server.builtup.users

but getting following error –

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘’’.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ‘saptech@123’

SELECT * FROM erpserver\server.builtup.users
‘.

pls help me on this
Reply



Leave a comment

et cetera