I need to do a join across two different database servers (IPs 10.0.0.50 and 10.0.0.51). What\'s the best way?
I know that the answers above are good, but wanted to share some details that I hope others will find helpful. Worth to mention is the user access part, which I think people will need help with.
set up the link:
exec sp_addlinkedserver @server='10.10.0.10\MyDS';
set up the access for remote user, example below:
exec sp_addlinkedsrvlogin '10.10.0.10\MyDS', 'false', null, 'adm', 'pwd';
see the linked servers and user logins:
exec sp_linkedservers;
select * from sys.servers;
select * from sys.linked_logins;
run the remote query:
select * from [10.10.0.10\MyDS].MyDB.dbo.TestTable;
drop the linked server and the created login users (adm/pwd)
exec sp_dropserver '10.10.0.10\MyDS', 'droplogins'; -- drops server and logins
resources:
sp_addlinkedserver
sp_dropserver
sp_addlinkedsrvlogin
sp_droplinkedsrvlogin