Learn more about Toad for SQL Server
at Dell Software

Find solutions and downloads at the
Toad for SQL Server Support Portal

Toad for SQL Server 6.6

You are here: Edit SQL > Reuse SQL > Use Code Snippets > Create Code Snippets

Create Code Snippets

To create a snippet

  1. Select View | Code Snippets from the menu (CTRL+ALT+T).

  2. Right-click a folder where you want to add a snippet and select New Snippet.

  3. Enter a name for the new snippet and press ENTER.

  4. In the syntax editor (top pane of the Design tab), compose the snippet. Specify the remaining properties as necessary. See Define Code Snippet Properties for more information.

To create a Surrounds With snippet

  1. Select View | Code Snippets from the menu (CTRL+ALT+T).

  2. Right-click a folder where you want to add a snippet and select New Snippet.  

  3. Enter a name for the new snippet and press ENTER.  

  4. In the syntax editor (top pane of the Design tab), compose the snippet. Now place the cursor within the snippet in the location of the text to be surrounded, and then right-click and select Snippet Tokens | Selected Token .

  5. Next, place the cursor in the location that you want the cursor after inserting the snippet. Right-click and select Snippet Tokens | End Token.

  6. Select SurroundsWith as the Snippet Type in the Properties tab (bottom pane).

  7. Specify the remaining properties as necessary. See Define Code Snippet Properties for more information.

    Note: To insert a SurroundsWith snippet, select the block of text in the Editor, then right-click and select Snippets | Surround with.

To import or export code snippets

Use the Snippets toolbar to:

Import snippets. Click to import snippets to the folder selected in the Code Snippets window.
Export snippets. Click to export your entire snippet library to a destination folder.

Define Code Snippet Properties

To define properties for a snippet

  1. Select the Design tab in the Snippet Properties dialog.

  2. Compose the snippet and define the snippet properties. Review the following for additional information:

    Syntax Editor  (top pane)

    Description

    Parameters

    Enclose the parameter name with $ characters. For example, to define a parameter named 'scope' enter $scope$).

    Tokens

    Right-click and select Snippet Token to add the following:

    • Selected Token ($selected$)—identifies the text to surround with a SurroundsWith snippet. An example of this is a snippet that turns a block of text into a procedure. Use a Selected Token to represent the block of text. In the Editor, when you select the block of text and insert the snippet, the snippet content surrounds the block of text just as it does the Selected Token.

    • End Token ($end$)—indicates the position of the cursor when you press ENTER to complete the activation of the snippet.

    System Variables

    Right-click and select System Variables to add the following:

    Date and Time

    Description

    %date%

    Date (short)

    %shortdate%

    Date (short)

    %longdate%

    Date (long)

    %time%

    Time (short)

    %shorttime%

    Time (short)

    %longtime%

    Time (long)

    %datetime%

    Date and time

    %utctime%

    Date and time (Universal time)

    Connection

    Description

    %connection%

    Connection name (short)

    %connectionlong%

    Connection name (long)

    %hostname%

    Host name

    %username%

    Current user name

    %database%

    Database name

    Misc

    Description

    %filename%

    File name

    %statement_
    separator%

    Statement delimiter, ”r;;”, ”r;\”, etc.

    %batch_
    separator%

    Batch separator (e.g. 'GO' in SQL Server)

    Properties Tab (bottom pane)

    Description

    Shortcut

    Enter the shortcut word or phrase. If defined, you can use the shortcut to quickly insert the snippet into the Editor by typing the shortcut, and pressing CTRL+SPACE.

    Keywords

    Enter any keywords associated with the snippet (space or comma delimited). You can search for snippets using keywords. See Insert Code Snippets for more information.

    Snippet type

    Select one of the following:

    • Expansion—replaces any text that is selected in the Editor.

    • Surrounds With—wraps the content of the snippet around the text selected in the Editor.

    Parameters tab (bottom pane)

    Description

    Identifier Enter the parameter identifier. This must match the parameter name in the syntax editor of the Design tab (without the $ delimiters). 
    Default Value Enter the default value of the parameter, if needed.
    Tooltip Enter a tooltip that displays when the cursor is placed over the parameter.

    Caution: Do not use the "1 of n" field to attempt to navigate parameters. This field specifies the order in which parameters are evaluated.

    Tip: To quickly add $ characters to identify a parameter, select the parameter in the syntax editor of the Design tab. Select the Parameters tab (bottom pane) and click +. All further instances of the parameter are automatically delineated with $ characters.

  3. Select the Test tab (top pane) to test parameter navigation and entry, as well as system variables/tokens.

Tips:

 

Related Topics

Insert Code Snippets 

of