Tuesday, 31 May 2011

SQL Server: Keep a Log of Your Executed Queries in SSMS

Every SQL Server DBA has experienced the odd Management Studio crash. They usually happen close to the end of a five hour session involving ten different tabs and a mountain of code. Occassionally, SSMS will look on you favouribly and restore some of your work. Usually, not.

A while back, I discovered an add-in for Management Studio which has helped me recover from these little frustrations. The SSMS Tool Pack is a suite of small utilities which generally make SSMS easier to work with. The most useful of these utilities is a query execution logger. It maintains two seperate logs. The first contains a copy of every query executed within SSMS. The second is a complete snapshot of the code sitting in the current tab.

As well as helping to recover from a SSMS crash, the logs can act as a memory aid. The execution log window allows you to search against execution date, server name and, of course, the code itself. Struggling to remember that smart-arse method you sussed out last year? Fire up the execution history window and tell it what you know.

By default, the Tool Pack's query log is saved to a file on the local drive. Although, it can be configured to save to a database table instead, which can speed up lookups and searches.

As well as the query logging tool, the Tool Pack contains 12 other handy utilities, including a code formatter, a tool to quickly store and recall snippets of code and a feature which adds a server-specific strip of colour to the each query tab - to help remind you that the DROP DATABASE command you are about to fire is going to be run on the live server.

The Tool Pack add-in is available for free download at http://www.ssmstoolspack.com. It's developed and maintained by one guy, Mladen Prajdić. So, if you get some use out of it, be sure to drop him a few Euros through his donations page.

No comments:

Post a Comment