BLOGS BY TOPIC▼
BLOGS BY AUTHOR▼
BLOGS BY YEAR▼
With SQL Server 2012 came the power not just to use pre-defined code snippets, but also to create your own - this blog explains how.
Posted by Andy Brown on 23 November 2017
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Creating custom snippets using Snippets Generator
Having seen how useful snippets can be, how do you go about creating them?
Installing the necessary software
You can download Snippets Generator from SQLArtBits:
At the time of writing, this is the link that you can click on to download the software.
You can then choose one of the servers to use:
Presumably it doesn't make much difference which download server you choose.
The rest of the installation is pretty standard.
Creating a snippet
To add a new snippet, run the Snippets Generator application, then choose the tab shown below:
Click on the New Snippet Details tab as shown here.
You can now fill in the details for your snippet:
The most important choice is the snippet type: do you want it to be a standard one, or to surround text that you have selected?
Now select some SQL in Management Studio:
This snippet is just the bare bones of a SELECT statement.
Paste this into Snippets Generator:
You won't see any formatting for your SQL in this view, but obviously it will come up when your paste your snippet into Management Studio.
Now save your snippet:
Click on this button at the bottom right corner of your dialog box to save this snippet.
Give this snippet a name, and choose where to store it:
Here I've put this snippet in the same folder as all of the others, for reasons that will become apparent soon.
Special considerations for SurroundText snippets
If your snippet is designed to surround SQL that you have selected, be careful not to remove the central marker:
For this type of snippet you can put anything you like before and after the $selected$ $end$ text; just be careful not to edit or delete the text itself.
Storing your snippets
The best place to put your snippets is in a new folder at the root level of your C drive:
By putting this Wise Owl snippety things folder at the root level of your hard disk, SQL Server Management Studio won't create a folder path for it when adding a snippet.
The next and final step of this blog shows how to import your snippets into Management Studio.