SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Simple question (connect to database)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Elidas
Starting Member

Spain
33 Posts

Posted - 05/13/2008 :  05:16:00  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Sweden
4110 Posts

Posted - 05/13/2008 :  05:27:27  Show Profile  Send jen a Yahoo! Message  Reply with Quote
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

Sweden
30207 Posts

Posted - 05/13/2008 :  05:29:03  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Use Spirit1's SSMSTools.


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

Elidas
Starting Member

Spain
33 Posts

Posted - 05/13/2008 :  07:38:45  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
7174 Posts

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

tkizer
Almighty SQL Goddess

USA
36832 Posts

Posted - 05/13/2008 :  12:59:08  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000