Avatar of whorsfall
whorsfall
Flag 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.
Databases

Avatar of undefined
Last Comment
hollween

8/22/2022 - Mon
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.
whorsfall

ASKER
Hi,

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

Thanks,

Ward
ASKER CERTIFIED SOLUTION
hollween

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
whorsfall

ASKER
Hi,


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

Ward
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
hollween