Working with Code Snippets

This topic explains how to use code snippets in dbForge Fusion for SQL Server.

Code snippets will help you type SQL code quickly. You can use predefined snippets provided in the application and create your own to insert them in SQL scripts and queries. Each snippet represents a statement or a group of statements fulfilling the same task such as creating a new user or describing a package. You can insert the required code snippet into your source code with a few mouse clicks.

Code snippets allow you to avoid wasting time while typing a code and learning unfamiliar code structures.

dbForge Fusion for SQL Server code snippets are XML files with a .snippet file name extension. They are created in accordance with the Visual Studio IntelliSense Code Snippet XML schema.

The Code Snippets window contains a plenty of templates organized in folders. In this window, you can arrange and preview snippets. To view a snippet, select it in the window. If a preview pane is not visible, right-click a snippet and select Toggle preview on the menu.

You can also drop, rename, add your own snippets, and modify existing ones using the snippets manager.

Inserting Code Snippets

  1. On the Fusion menu, select Other Windows, and click Code Snippets.The Code Snippets window opens.

  2. In the Code Snippets window, choose the required template and drag it to the SQL editor.

  3. Specify variable names and parameter values in the lines marked green and press ENTER to complete code fragment editing.

  • or -
  1. Right-click in the SQL editor and click Insert Snippet on the menu.

  2. Select the required template.

  3. Use the UP ARROW and DOWN ARROW keys to select the desired item in the snippets list.

  4. Specify variable names and parameter values in the lines marked green and press ENTER to complete code fragment editing.

Code snippets can also be inserted by entering template shortcut word or words and pressing the TAB key. To see snippet shortcuts, right-click in the SQL editor and choose Insert Snippet on the menu. A snippet hint contains snippet shortcuts.

Note

If you want some fragment of the code to be put inside the inserted template, select it with the mouse before placing a snippet to the editor. If the snippet does not provide surrounding, the selected text will be deleted.

To move the snippet to the root folder of the Code Snippets window, drag it to the one that already is in the root folder or to the upper border of the Code Snippets window.

Creating Code Snippets

  1. On the Fusion menu, select Other Windows, and click Snippets Manager. The Snippets Manager window opens.

  2. Click New Snippet on the manager toolbar.

    Snippets Manager

    Note

    Actual document look may slightly vary from the above image, depending on the product you use.

  3. In the Text field, enter the text of the snippet.

  4. Specify a shortcut and snippet description in the corresponding Shortcut and Description fields.

    Note

    The Location field is read-only and is filled automatically when you choose the folder available in the list of snippets.

    Note

    The shortcut (if any) will be taken as snippet name. If there is no shortcut specified, the new snippet will be named Snippet. To change the snippet name, double click it in the list of snippets and enter the needed name.

  5. Click Save on the toolbar.

Editing Code Snippets

  1. On the Fusion menu, select Other Windows, and click Snippets Manager. The Snippets Manager window opens.

  2. Select the needed snippet from the list of available snippets.

    Snippets Manager

    Note

    Actual document look may slightly vary from the above image, depending on the product you use.

  3. Modify the snippet’s description, shortcut, and text in the corresponding fields.

  4. Click the Save button on the manager toolbar.

  5. To change the snippet name, double-click it in the list of available snippets.