Colored Query Windows in Microsoft SQL Server 2012

As s software developer or DBA, we are always in situation of having a lot of Query Windows open and being connected to several instances of SQL Server such as Local instance, Acceptance instance, Production instance and so on.

Typically we use only one instance of SQL Management Studio to connect to all instances of SQL Servers. Therefore most of the time there are even more than 10 Query Windows open inside the Management Studio.

Because all Query windows are pretty the same, we are likely to execute a query mistakenly in a wrong window (e.g. running a query against the live database instead of the local one) and that can cause a disaster which sometimes is irreversible and sometimes costly reversible.

This is not the only case which this kind of problems can happen. Sometimes Management Studio is open for a while and we forget to close the query windows related to the live database. Then after a few days (or even few hours) we come back to the windows and just run a query, not having a clue which we are running the query against the live database.

As a matter of fact we can mention a numerous cases that can result the above explained problem. If you have been working for years with SQL Management Studio, I am sure you also have at least a bit experience in this regard.

A few days ago I noticed there is a nice and cool feature in SQL Server 2012 which allows us to specify color for each instance of SQL Server at Query Windows. That means when we open a Query Window for specific instance of SQL Server, the statusbar of the window will be in a particular color. With a quick look at statusbar we can simply understand where we are running the query. In the image below, we have changed the default color to Red.

To Achieve this result, go to the View menu in SSMS and choose Registered Servers option. Now the Registered Servers window is open, you should first register the SQL Server instances (If you have not already registered them).

To do so, right click over the Local Server Groups and choose the New Server Registration option. Now in the opened windows you can simply enter the Server name, Authentication etc.



Then go to the Connection Properties tab and you can see the Use Custom Color checkbox. Select this option and choose a favorite color for this instance. The color can be conventional for the instance and for example you can choose Red for production, Green for local instance and so on.

Now if you open a new Query Window for every registered SQL Server instance, you can see the colored bar down at the bottom and simply understand where the query is going to be executed.

 

If you have already registered your instances, you can simply right click over the particular instance and choose Properties option. Then you can go to the Connection Properties tab and do the same.

I found this feature very helpful and hopefully you do as well.

2 Comments

  • You could also try window coloring from SSMSToolspack. It's faster to implement if all your test servers are on a specific domains like test.DOMAIN it would color all that have the word test in them.

  • The feature actually exists even back in 2008 R2, so it's not a new feature - making your title and the state in the blog entry wrong.

    However, as it's a bit "hidden" and not self-describing within the Connection Properties, it's good to make more awareness of the feature, making it much clear when using several database servers at the same time. Probably not many are using it yet.

    Just wanted to let you know :)

Comments have been disabled for this content.