I’ve written previously about ways to protect yourself in case of firing off queries against incorrect SQL instances or the correct instances before the time is ready. I showed you how to manipulate the code in the default "New Query" that is opened as a blank query as default to allow you to add safeguards such as default transactional processing with a rollback command or having the text of the "New Query" be commented in full until you change it. Like I said, safeguards.
There seldom is one way to do things, though. What if you were able to have a visual reminder of whether you were connected to a production, stage, test, or Q/A instance of SQL Server—a cue that you have the chance of doing very bad things should you hit that F5 (Execute) command? That's what I’ll be showing you how to do today.
Registered Server Explorer and Color Coding Instances
You should be familiar with registering a new SQL Server in SQL Server Management Studio (SSMS) by now. If not, then inside of SSMS, select View\Registered Servers from the menu upon launch, and then expand Database Engine, right-click, then finally, select New Server Registration from the auxiliary menu that is displayed. You'll be presented with the modal window:
I'll leave it to you to make sense of this screen. Its common sense and not relevant to our discussion here today. Instead, I want to talk about the other tab in this window, the Connection Properties tab. This tab is mostly overlooked by most of us who use the Registered Servers Explorer. However, this is where you have the ability to build some safeguards when using SSMS.
The Connection Properties Tab
While in the Connection Properties tab, select Use custom color. Next, open the palate through the Select button at the right of the menu; select an appropriate color for each environment you tend to partition your servers. In my environments, I tend to use the following framework for color cues:
- PRODUCTION – Red
- STAGE - Yellow
- DEV – Blue
- TEST or Q/A – Green
Of course, what your preferences are is completely up to you. Matter of fact, I have a touch of color blindness, so for those of us out there with the same tendencies or limitations, you may find something that works better for you.
You'll see in the example I'm using here that I've selected to connect to a production database. In doing so, I wanted to then signify that this is a production database and also created a relatively obvious alias and then set its "connection color" to red. It should now be obvious to even the most self-centered and oblivious, that this is an important SQL instance. Once I save these changes off, you'll notice the visibility that results in the Registered Servers explorer (some entries have been redacted to protect the author):
Now, launch a new query and you’ll see where the color coding comes into play:
The status bar will display in the color coding setting you configured for this SQL registration. It's a very visible reminder of the importance of this instance that you've set up visible cues for through a simple configuration setting.
Simple Way to Protect Yourself
Protecting yourself is a very simple task. The color coding setting takes seconds to do and provides protection for a long time to follow. It's just another reminder that taking a few small steps can yield big results.