Mihir Solanki

mihirsolanki.com

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Links

Subscriptions

Post Categories



SQL Server FAQ : How to join tables from different servers?

To be able to join tables between two SQL Servers, first you have to link them. After the linked servers are setup, you just have to prefix your tables names with server name, database name, table owner name in your SELECT queries. The following example links SERVER_01 to SERVER_02. Execute the following commands in SERVER_02:

EXEC sp_addlinkedserver SERVER_01
GO

/* The following command links 'sa' login on SERVER_02 with the 'sa' login of SERVER_01 */
EXEC sp_addlinkedsrvlogin @rmtsrvname = 'SERVER_01', @useself = 'false', @locallogin = 'sa', @rmtuser = 'sa', @rmtpassword = 'sa password of SERVER_01'
GO

SELECT a.title_id
FROM SERVER_01.pubs.dbo.titles a
INNER JOIN SERVER_02.pubs.dbo.titles b
ON a.title_id = b.title_id
GO

posted on Thursday, December 08, 2005 3:02 AM by mihirsolanki


# re: SQL Server FAQ : How to join tables from different servers? @ Tuesday, October 02, 2007 9:29 PM

question my server_01 is my local server and my server_02 is 'SERVER\SERVER09' which uses windows log-in... when i execute your code i this error keep on showing.. Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '\'. please help

SOCRAM

# re: SQL Server FAQ : How to join tables from different servers? @ Thursday, December 06, 2007 6:27 AM

I get the error "Login failed for user ''. The user is not associated with a trusted SQL Server connection.".How i can solve this problem?.

Ezhil




Powered by Dot Net Junkies, by Telligent Systems