Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Simple question (connect to database)

Author  Topic 

Elidas
Starting Member

33 Posts

Posted - 2008-05-13 : 05:16:00
How can I connect to another sqlserver instances using a SQL Query Analyzer command? I mean, something like this:



connect (server1.instance1, user, pass) ??
SELECT * FROM MYTABLE;
connect (server1.instance2, user, pass) ??
SELECT * FROM MYTABLE;
connect (server1.instance3, user, pass) ??
SELECT * FROM MYTABLE;

PD: I know I can click in File-->Connect-->etc..., but I want to do this with a T-SQL command

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2008-05-13 : 05:27:27
right click on the query window, change connection
or
use linkedserver to query other dbs in other servers
else
afaik, not possible


quote:
Originally posted by Elidas

How can I connect to another sqlserver instances using a SQL Query Analyzer command? I mean, something like this:



connect (server1.instance1, user, pass) ??
SELECT * FROM MYTABLE;
connect (server1.instance2, user, pass) ??
SELECT * FROM MYTABLE;
connect (server1.instance3, user, pass) ??
SELECT * FROM MYTABLE;

PD: I know I can click in File-->Connect-->etc..., but I want to do this with a T-SQL command



--------------------
keeping it simple...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-13 : 05:29:03
Use Spirit1's SSMSTools.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Elidas
Starting Member

33 Posts

Posted - 2008-05-13 : 07:38:45
I cant belive it is impossible to make a new connection to a different server from query analyzer, what I am asking is a simple command like for example has oracle in sqlplus: "connect sys\password@database"
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-13 : 12:52:24
setup linked server and use four part name like [instance].[database].[schema].[object].
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-13 : 12:59:08
Use OPENQUERY.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -