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 :)


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'
    SELECT *
    FROM YourTable

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

|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

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.

|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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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