Navicat Blog

March 14, 2018 by Robert Gravelle

When the Non-Essentials edition of Navicat Premium introduced the Code Snippets feature, writing queries against your preferred database type became easier than ever before. The Code Snippets feature allows you to insert reusable code into your SQL statements when working in the SQL Editor. Besides gaining access to a collection of built-in snippets, you can also define your own snippets. Today's blog will provide an overview of this exciting new feature.

The Code Snippet Pane

Located on the right-hand side of the SQL Editor, the Code Snippets Pane provides an easy way to insert reusable code into SQL statements when working in the SQL Editor. If the editor window is docked to the Navicat main window, you can click the () icon in the Information pane (#1 in the image below) to view the snippets library.

The snippets library includes built-in and user-defined snippets. If you would like to reduce the number of entries in the list, you can enter a search string in the Search box to filter the list (#2 in the above image). You can also show the available snippets according to your database type or for all database types. Right-click anywhere on the library and select "Show Snippets For Other Database Type" from the popup menu to either show or hide snippets for other database types. A checkmark beside the item indicates that "Show Snippets For Other Database Type" is active.

Inserting a Snippet into a Query

There are two ways to insert a snippet into the editor:

  • Just start typing the name of a snippet in the editor. Smart Code Completion will present a list of suggestions for you to choose from. Select a snippet name from the list to insert it in the editor.

  • You can also drag and drop a snippet from the library into the editor. After inserting the snippet with placeholders in the editor, you can navigate between them by clicking on a placeholder and then using the TAB key to iterate over each. Typing while a placeholder is selected will overwrite it with the typed characters.

Adding a Snippet

You can create your own code snippets and add them to the library. To add a code snippet, select your desired code in the editor, then right-click and select "Create Snippet" from the popup menu.

Alternatively, you can click the Create Snippet in the Code Snippet pane (#3 in the Code Snippet pane image above) to open the New Snippet dialog directly. You may then assign a title and label type to your snippet. Type the code in the New Snippet window and then click the Save button to save your code snippet to the library.

Editing a Snippet

Double-clicking a snippet in the library opens the Edit dialog. Built-in snippets are read-only, as is indicated in the dialog title.

Moreover, you can hide the built-in snippets in the Snippets Pane by right-clicking anywhere on the library and disabling the "Show Preset Snippets" item in the popup menu.

Navicat Blogs
Feed Entries
Blog Archives