Manage SQL snippets

dbForge Studio for SQL Server lets you:

  • Create your own SQL snippets.
  • Modify snippets.
  • Delete snippets or folders.
  • Group snippets into folders.
  • Create, modify, or delete literals (placeholders) for snippets.
  • Change the location of snippet files.
  • Sort snippets by shortcut or title, in ascending or descending order.

Create a snippet

1. Select Tools > Snippets Manager.

The expanded Tools menu

2. Select a folder where you want to store the new snippet.

3. Click New Snippet.

Open Snippets Manager

4. In Title, enter a name for the snippet.

5. In Shortcut, enter a short name or combination of characters to quickly invoke the snippet.

The shortcut will be displayed in the suggestion box.

6. In Description, enter additional details about the snippet.

7. In Text, enter a code fragment.

8. To insert a literal (placeholder), place the cursor where needed in the Text section and double-click the literal in the Literals section.

9. Click Save.

Save the code snippet in Snippets Manager

Modify a snippet

1. Select Tools > Snippets Manager.

2. In the tree, select a snippet.

3. Modify the snippet parameters.

4. Click Save.

Delete a snippet or folder

1. Select Tools > Snippets Manager.

2. In the tree, select a snippet or folder.

3. Click Delete, then click Yes.

Delete a snippet in Snippets Manager

Group snippets into folders

1. Select Tools > Snippets Manager.

2. Click New Folder.

3. Enter a folder name.

Group snippets in Snippets Manager

4. Drag snippets into the folder.

Snippet literals

Literals are placeholders used in snippets. After you insert a snippet, a placeholder is replaced in the SQL document with its default value. You can then modify the placeholder value.

Predefined literals

Placeholder Description
$CARET$ Specifies where the cursor moves in the text after you press Enter to finish editing the inserted code fragment.
$DATE$ Inserts the current date in the yyyy-mm-dd format.
$TIME$ Inserts the current time in the hh:mm:ss format.
$USER$ Inserts the name of the user who is currently connected to the SQL Server instance.
$DB$ Inserts the name of the database to which the current query tab is connected.
$SERVER$ Inserts the name of the SQL Server instance to which you are currently connected.
$LOGIN$ Inserts the user’s login to connect to the SQL Server instance.

User literals

You can create, update, or delete custom literals for a snippet.

Create a literal

1. In the Snippets Manager, select the snippet for which you want to create a literal.

2. Click Add.

3. Fill out the fields:

  • Name – A name of the user literal.
  • Default value – A default value for the placeholder that is inserted with the snippet.
  • Description – A short description of the literal. You can view it by hovering over the literal in the User section of the Snippets Manager.

Create a literal for the snippet

4. Click OK, then click Save.

Modify a literal

1. Select the literal you want to modify.

2. Click Edit.

3. Modify the literal parameters.

4. Click OK, then click Save.

Delete a literal

1. Select the literal you want to delete.

2. Click Remove, then click Save.

Change the snippet file location

Snippets are invoked from and saved to the location specified in the Snippets Manager.

By default, snippet files are stored at C:\ProgramData\Devart\dbForge Studio for SQL Server\Snippets.

To set a different file location:

1. Select Tools > Snippets Manager.

2. Under Location, click the The ellipsis icon ellipsis button.

3. Select the needed folder.

Note

You can use only snippets from the currently selected location.