This isn’t really one of those features of SSMS that I’ve used a great deal. At least didn’t until recently. For those that don’t know, if you right-click on the tab of a query window you will get, among other things, options for a new tab group.
If you pick for example New Horizontal Tab Group you will get this:
I’ve circled the original tab group in red and the new one in blue.
Up until recently the only use I have found for this is to compare two scripts. Put one in the first tab group and the other in second tab group and manually scan through them both.
In the last couple of weeks I’ve started doing some work for a group that I haven’t dealt with before and things are bit different from what I’m used to. First of all their expectations are a bit quicker than our usual customers. Instead of having an expectation of 4-6 hours to get a relatively simple request done, their expectations are closer to an hour or less after they make the request. On top of that instead of getting one script to run, they tend to present me with groups of scripts to be run on a given database, sometimes in a specific order, sometimes not.
Now I’m one of those people who keeps most, if not every script I work on throughout the day open until the end of the day. Not the most efficient thing in the world I realize, but I’ve had too many occasions where I’ve NEEDED one of those scripts from earlier in the day. So recently I had a situation where I had about 15-20 scripts open, and then was asked to run 20-30 more scripts, each one in its own file. Trying to open, review and execute them all, in and among my existing open scripts could have gotten really really messy.
I found though that if I opened up a new tab group with a query window connected to the server/database that I needed. Then dragged and dropped my new files (containing the scripts) into that tab group. Then all the new files opened in the new tab group and where not only connected to the server/database I needed but stayed separate from the rest of what I was working on.
I’m going to walk through this with a couple more images since I think it’s a bit confusing the way I’ve described it.
Use the image above for the starting point. I’ve got 2 tab groups. The top one has all of my old scripts and the bottom one has one empty query window. I connect that query window to the server and database that I need.
I’ve scripted out all of the stored procedures for Adventureworks2008 as an example. I open the folder with all of the scripts and select them all.
By dropping the files on a query window they will be opened not only in that tab group but connected to the same server and database. Now I can review, execute and close each of the scripts in the tab group quickly. Cntrl-E to execute and Cntrl-F4 to close the query window once I have a successful run. I don’t have to worry about mixing up the scripts I need to run with the ones I’m working on for someone else. Not to mention that once I run out of scripts in the tab group I’m done.