SQL Server

How to switch between different SQL Servers within a query window in SSMS

In this post i will write about how to switch between different SQL Servers within a query window in SSMS or in another words i can say how to run a T-SQL command from the same window at different sql servers in SSMS.

Let us consider the following image. If i put my mouse over the query window tab of SSMS, it will give me a tooltip that i am connected currently to the master database of the Test server. This is highlighted in the red block.

 

switch between different SQL Servers within a query window in SSMS 1

After executing the SQL script at Test Server,  i want to run the same command at Production Server .Therefore i need to switch the server from Test to Production. So i will use the same query window to run the same T-SQL command in SSMS.

Click on the change connection in SSMS as highlighted in the red block. When you put your mouse over the icon highlighted in the red block, a tooltip as “Change Connection” will also appear as shown below.

 

run a T-SQL command from the same window at different sql servers in SSMS 2

 

After that Connect to the Database Engine will appear. Mention the SQL Server Name with which you want to connect  with appropriate Authentication mode. In my case i am using Window Authentication and connecting to Production Server as shown below. After that hit connect.

 

switch between different SQL Servers within a query window in SSMS 3

 

Now if i put my mouse over the query window tab of SSMS, it will give me a tooltip representing that i am connected currently to the master database of the Production Server. This is highlighted in the red block as shown in the following image.

 

run a T-SQL command from the same window at different sql servers in SSMS 4

 

 

In this way you can switch between different SQL Servers within a query window in SSMS.

Important Note:Double check with which server you are currently connected by putting the mouse over the query window tab of SSMS and looking carefully at the tooltip to make sure that you are connected to the correct server

One thought on “How to switch between different SQL Servers within a query window in SSMS

Leave a Reply

Your email address will not be published.