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 :)
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.
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.
The code will run on all the instances, but the ones without the correct name won't actually get run the select statement.