Link to home
Start Free TrialLog in
Avatar of whorsfall
whorsfallFlag for Australia

asked on

Transact-SQL - connect to a different SQL server.

Hi,

I am wondering how can the following be done from Transact-SQL (SQL 2000). From the query window connect to a different SQL server using T-SQL code.
Like the "USE" command but switching servers instead of just databases. (I want to have a big SQL script that can connect to multiple SQL servers) without
having to do lots of mouse clicking etc :)

E.g. (I know the syntax is wrong).

USE <SQL Server>
USE <Database>


Thanks,

Ward.
Avatar of hollween
hollween

You can setup a link server in the sql manager, and you need an user id that would allow you to access the linked sql server.  After the link server is setup, you can use as:

select * from ServerAlias.Database.Owner.Table.
Avatar of whorsfall

ASKER

Hi,

Thanks for your answer. Can that Link creation be scripted in T-SQL as well?

Thanks,

Ward
ASKER CERTIFIED SOLUTION
Avatar of hollween
hollween

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,


Thanks for your help - so can you give me some same code to make the link - that would be great :)

Ward