SQL Prompt 9

Managing snippets

 A SQL Prompt snippet is a block of code you can insert into your query. To insert a snippet, type the snippet name (eg ssf) into your query and press Enter or any other insertion key:

Snippet Manager

To see the list of snippets you can use, go to the SQL Prompt menu and select Snippet Manager. You can find specific snippets by searching for both name or description:

Creating a snippet

You can create a snippet from code you've typed into the query editor. Highlight the block of code, right-click and select Create Snippet.

The default snippet name is created automatically from the initial letters of the selected text. You can edit this if you want to use a different name.

You can use placeholders in your snippet code.

Creating a new snippet

  1. On the SQL Prompt menu, select Snippet Manager.
  2. Click New.
  3. In the Snippet box, type the text that will insert the snippet.
  4. Optionally, type a short description of your snippet in the Description box.
    The description helps you to identify a snippet if you are unsure of the snippet name. You can leave the Description box blank if required.
  5. Type or paste the SQL code in the Code box.

    In your snippet code you can specify:

  6. Click Save.

Using placeholders

You can use placeholders in your snippets to insert values into your code, change the caret position, define a selection, and more.

Default placeholders

To view the list of default placeholders, in the Code box, type $:

You can use the following placeholders in snippet code:


Specifies the cursor position when the snippet is inserted.

For example, SELECT $CURSOR$ FROM places the cursor after SELECT.


Inserts the current date.

You can specify a custom date format, for example $DATE(MM/dd/yyyy)$.  

$DBNAME$Inserts the name of the connected database.
$GUID$Inserts a globally unique identifier.
$MACHINE$Inserts the name of machine running SQL Prompt.
$PASTE$Inserts the contents of the clipboard.

Inserts the selected text.

 You can use this placeholder to create a snippet that encloses your selection in a block, eg BEGIN...END.

 Snippets using this placeholder are included in the actions list .



Selects a block of the snippet text.

For example, $SELECTIONSTART$SELECT TOP 100 * FROM Table1$SELECTIONEND$ is inserted as:

$SERVER$Inserts the name of the connected SQL server.

Inserts the current time.

You can specify a custom time format, for example $TIME(HH:mm:ss)$.

$USER$Inserts the name of the connected user.

Creating a placeholder

To create a placeholder, in the Code box, surround the name of the placeholder with $, for example $myplaceholder$:

Use the Placeholders list to enter default values and change the order in which your placeholders are inserted:

Getting more snippets

Snippet repository on GitHub

If you're using Git, you can clone a repository of useful snippets contributed by Gaurav Vohra.

Thanks Gaurav!

tSQLt snippets for SQL Test

If you're using SQL Test, you can download a set of useful snippets from the tSQLt website (under Other Downloads).

The snippets include pre-defined code for:

  • test creation and execution
  • assertions
  • isolating dependencies

Didn't find what you were looking for?