Create your own snippets of SQL code, and insert them into your queries
Part four of a four-part series of blogs

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.

  1. Creating your own snippets of SQL
  2. Three examples of the use of snippets
  3. Creating custom snippets using Snippets Generator
  4. Importing SQL Snippets into Management Studio (this blog)

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.

Importing SQL Snippets into Management Studio

Having created one or more snippets, here's how to use them!  First select this menu option in SQL Server Management Studio:

SSMS import snippets

I'm using SSMS for SQL Server 2016, but it should be the same in older and newer versions (provided that you're on at least 2012).

Now choose to add the snippets that you've created:

Add snippets

The choice of language at the top isn't particularly inspiring: SQL or SQL ...

 

Browse to the folder containing your snippets, and select it:

Snippets folder selection

You can also add individual files, but it seems easier to put all of your snippets into a single folder.

This folder (and any of its subfolders) should immediately appear in the list:

The new folder added

It's a shame Wise Owl comes so late in the alphabet. We did consider calling ourselves Aardvark Training way back in 1992 - perhaps we should have!

 

You can now add your custom snippets!

Custom snippets

The snippet will appear in the appropriate submenu, according to whether it's type is Expansion (as here) or SurroundText.

 

If only everything in IT was this simple and easy to use!

This blog has 0 threads Add post