Published 18 May 2015
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. 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
- On the SQL Prompt menu, select Snippet Manager.
- Click New.
- In the Snippet box, type the text that will insert the snippet.
- 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.
Type or paste the SQL code in the Code box.
- Click Save.
You can use placeholders in your snippets to insert values into your code, change the caret position, define a selection, and more.
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.
Inserts the current date.
You can specify a custom date format, for example
|Inserts the name of the connected database.|
|Inserts a globally unique identifier.|
|Inserts the name of machine running SQL Prompt.|
|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.
|Inserts the name of the connected SQL server.|
Inserts the current time.
You can specify a custom time format, for example
|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.
tSQLt snippets for SQL Test
The snippets include pre-defined code for:
- test creation and execution
- isolating dependencies