Switch Query Environment in SSMS

Peter Schmitz

Staff member
Learnt this today from a consultant, and since it's a quick little trick, I figured I'd share it.

When you work in different environments, you sometimes want to test your query from DEV in QA, or from QA in Prod to verify the actual data. I used to copy the query to Clipboard, then connect to the other server, paste the query back in, and then finally set the proper database context. That's a lot of mouse-clicks for something that can be achieved a lot faster.

Right-click anywhere in the window with your query in it. In the properties menu, pick "Connection", and then "Change Connection":


You will see the regular connection window. The one thing to keep in mind is that you still need to manually adjust the context of the database the query will be run in.