Importing Templates into Sql Server Management Studio

You can add templates to the template explorer by navigating to a directory and putting the files directly into a folder.

On Vista/Windows 7 the folder is:

C:\Users\user\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql

“user” should be replaced with your username and the 100 directory is for Sql Server Management Studio 2008 and you replace it with 90 for 2005!

On XP it is:

C:\Documents and Settings\user\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql

“user” should be replaced with your username and the 100 directory is for Sql Server Management Studio 2008 and you replace it with 90 for 2005!

You will have to restart management studio for the templates to come up. If you have 2005 and 2008 management studio and you use both then you will have to put the templates in the folder for each version also.

Advertisements

Saving an Sql Script in a Different Encoding

In some situations I create scripts and store them in a folder. Later I will concatenate the contents using a batch file which doesn’t work very well if the files do not use the same encoding.If you have one in Codepage 1200 and another in Codepage 1252 then you will have some very odd characters in your resulting script

When writing a script in Sql Server Management Studio, you can save them with different encoding. I learnt the idea of a previous employee at work and found it useful.

By default Management Studio seems to want to save new scripts (press “New Query” button) as “Western European (Windows) – Codepage 1252”, yet when you click “Modify” to edit a stored procedure, for example, and then try and save the script it will, by default, save as “Unicode – Codepage 1200″… and these don’t concatenate together very well as already explained.

There seems to be know way within Management Studio to set a default for this, so unless I’m mistaken, we are stuck doing things manually. Here is how:

When you have the Save File dialog, click the little drop down box at the right of the “Save” button, and click “Save with Encoding…” option.

Sql Management Studio - Save with Encoding...

Sql Management Studio - Save with Encoding...

You can now select the type of encoding.

I had done a fair bit of work with Management Studio before I came across this small drop down on the save button. It’s not really obvious as I was expecting a drop down box on the actual dialog. Hopefully this will be helpful to someone else also.