The Snippet Manager in SQL Prompt

I love SQL Prompt, since it makes T-SQL coding quicker and easier. One of the handiest things is the Snippet Manager. I’ll show you how this works.

When I type something, like “cl”, I get a list of things, as shown below..

2016-09-23 10_24_42-SQLQuery3.sql - (local)_SQL2014.Sandbox (PLATO_Steve (61))_ - Microsoft SQL Serv

I see CLOSE, which has “cl” in it, as well as a number of functions. However there are two items (cl and clrp) that have a description to the right. They also have a scroll to the left. These are snippets. If I hit Tab, the highlighted snippet, cl, will be replaced with code. This is shown below.

2016-09-23 10_19_22-SQLQuery3.sql - (local)_SQL2014.Sandbox (PLATO_Steve (61))_ - Microsoft SQL Serv

This is all custom code I put into my Snippet Manager. I can now replace these parameters with new values, or just execute this code as is to create a new login and user. Note I typed three things (c, l, TAB) to get lots of code here.

The Snippet Manager

To access the Snippet Manager, click the SQL Prompt menu item and look down towards the bottom.

2016-09-23 10_27_33-SQLQuery3.sql - (local)_SQL2014.Sandbox (PLATO_Steve (61))_ - Microsoft SQL Serv

This will bring up the Snippet Manager (part of SQL Prompt options in 7+). Note that I have a folder where I store snippets at the top, various snippets below that (with new/edit/delete buttons) and then the snippet code the the highlighted snippet at the bottom of this image.

2016-09-23 10_27_41-SQL Prompt – Options

The snippet is highlighted, and if I type, I get completion here. So, I’ll type C-D, and jump to the “cdb” snippet. Note I’ve skipped over cci.

2016-09-23 10_29_53-SQL Prompt – Options

I can then edit or delete this snippet. If I edit it, I’ll get a dialog with the snippet and the placeholder parameters listed. This is shown below.

Note: I’ve customized this code, so it isn’t the SQL Prompt default.

2016-09-23 10_31_02-SQL Prompt - Edit Snippet

I can also create new ones. For example, on one of our Redgate VMs, we keep some demo snippets. I’ll can create a new one by clicking “New…”

2016-09-23 10_32_05-SQL Prompt – Options

I’ll then get this dialog.

2016-09-23 10_32_12-SQL Prompt - Create New Snippet

I can give this a name, a description, and type any code into the code window. I’ve added a few items below.

2016-09-23 10_35_15-SQL Prompt - Create New Snippet

Now if I save this, close the Snippet Manager, and go back to a Query Window, I can type d-e-m, and see this:

2016-09-23 10_36_53-SalesDemo-2016-09-07-1117-export-i-fh727xw9 - VMware Workstation

My new demoxpcmdi appears before the other “demo” snippets. I can also see my description to the right.

Hopefully, you’ll see the value in SQL Prompt and start using snippets to improve your ability to code quickly and take the hassles and guesswork out of cleanly building SQL Code. You can also read a similar piece I wrote on the Redgate blog.

Try a SQL Prompt evaluation today and then ask your boss to get you this productivity enhancing tool, or if you’re using the tool, practice using ii the next time you need to insert some data.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , , . Bookmark the permalink.