SQL Prompt 7

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:

To see the list of snippets you can use, go to the SQL Prompt menu and select Snippet Manager.

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:

Sharing snippets

You can share your snippets with other SQL Prompt users by storing them in a shared folder (a network share, SkyDrive, or Dropbox, for example).

To use a shared folder:

  1. On the SQL Prompt menu, select Snippet Manager.
  2. Under Snippet folder, copy the path to the snippet folder:

  3. Open the snippet folder and copy the snippet files you want to share.

    Snippets are stored as XML files with the .sqlpromptsnippet file extension.

  4. Open the shared folder you want to use (a network share, SkyDrive, or Dropbox, for example), and paste the snippets into it.
  5. In the Snippet Manager, under Snippets folder, browse to the location of your shared folder:

 Other SQL Prompt users can use the same set of snippets by changing their snippets folder to the shared folder.

To restore the snippets folder to the SQL Prompt default location, click Restore default. This also adds any missing default snippets back into the folder.

When you restore the default snippets, your custom snippets aren't removed and any changes you've made to default snippets aren't overwritten.

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?