Sunday, January 13, 2008

SQL Server Management Studio Templates - My Small Gripe

January 13, 2008 Posted by Jason Irwin No comments

I love SQL Server. I love SQL Server Management Studio for the most part. I love the idea of templates in SQL - allowing query templates to be created with variable fields which, with a simple CTRL-M can be populated in a handy dialog. This is a feature I would use all the time…if it were not for my propensity to overwrite the template when saving the resulting file. I do not advocate sloppy coding, nor am I a sloppy code. But every now and again, when things are really busy, I will find that I have saved a file out for future use, forgetting that it was a template to begin with….

I know what you're thinking - the obvious thought would be to set the SQL Script to read-only - allowing changes to be made and executed, but never saved. Unfortunately, in SQL 2005 at least, making the file read only and attempting to populate said variable fields, results in the following message (and no, the file is most certainly not under source code control):

This I cannot explain, and I'd be interested to hear if anyone else has this issue. Personally, and I know this is wishful thinking, I would like to see some separation of template and resulting code (even the option to output the generated code to a separate query window. It's a very small point, but one that (to me) would add quite a bit of finish to this feature. And that is my gripe for today!