Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In SQL management studio, you can open a New Query by right clicking on the Server Group itself rather than a registered server. When you do so, at the bottom right, you can see the user as <various logins> and the database as <multiple>.

In this case, how should the query window be used? Do we need to specify that we are running the query as a particular user and if yes, then how?

Thanks :)

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you have a query window connected to multiple instances there isn't a way to force it to only one instance. About the only way to do this would be with an IF block.

IF @@SERVERNAME = 'TheCorrectInstance'
BEGIN
    SELECT *
    FROM YourTable
END

The code will run on all the instances, but the ones without the correct name won't actually get run the select statement.

share|improve this answer
    
Thanks :) Why is this feature provided? I can see only one use - comparing data across servers. Anything else? –  Rashmi Pandit Aug 2 '11 at 8:33
    
So that you can quickly gather info from all your servers, or so that you can make massive config changes across all your systems like adding a SQL Agent job to every server, stuff like that. –  mrdenny Aug 2 '11 at 23:24
    
Hmm ... I see ... Thanks again :) –  Rashmi Pandit Aug 3 '11 at 3:28

No, once you are logged in to a database server in Object Explorer using one set of credentials, that's the user you'll be using. You can open multiple query windows, and switch databases (subject to permissions)

If you want to use a different user to the same database server, you can open a new connection in Object Explorer, and it will keep it separate. You'll open more query windows.

share|improve this answer
    
If you right click on the server group, it opens up a query window using all the user accounts and databases configured in that server group. This is the case with 2008 and not 2005. If you query a table where the table name is same in 2 different databases, it gives me a consolidated result of both the tables. I need to know how to avoid that and get results for a specific database using a specific account, but still using the same query editor. –  Rashmi Pandit Aug 2 '11 at 6:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.