SQL Prompt 5

Inserting suggestions into your code

SQL Prompt provides SQL code auto-completion using the suggestions box. The suggestions box pops up to display items based on what you type in your query editor.

For example, when you type SELECT * FROM, the suggestions box displays a list of tables first, then views, and further down the list, owners, databases, functions, and so on.

The suggestions box is displayed automatically when you type in a query window. As you type, the suggestions are filtered to match the typed characters.

Types of suggestions

Only prefix suggestions are available before SQL Prompt 5.3.

Suggestions are listed in the following order in the suggestions box:

  1. Prefix suggestions
    For example, if you type se, the SELECT keyword is suggested:
  2. CamelCase, or compound word suggestions
    For example, if you type mt, the object MyTable is suggested:
  3. Mid-string suggestions
    For example, if you type vent, the AdventureWorks database is suggested:

    Mid-string suggestions are particularly useful if you can only remember part of an object name.

To insert the currently highlighted suggestion, press the Tab or Enter key, or any of the defined insertion keys. You can customize which keys insert suggestions, see: Managing SQL Prompt behavior.

Closing the suggestions box

To close the suggestions box without inserting anything, press the Esc key. If nothing is selected in the suggestions box, you can also press the Enter key to close it.

You can also click anywhere in your query window to close the suggestions box.

Order of suggestions

The order in which suggestions are listed depends on the context of your query. For example:

  • After typing USE, databases are listed at the top of the suggestions box.
  • After typing SELECT * FROM, tables are listed at the top of the suggestions box, followed by views, schemas and then database names.
  • In a CREATE TABLE statement, after typing a column name, data types are listed at the top of the suggestions box.

Viewing all columns after a SELECT statement

After typing SELECT, SQL Prompt does not by default list all the possible columns from all tables. If you want to see all column names after typing SELECT:

  1. From the SQL Prompt menu, click Options.
  2. Go to the Suggestions > Types of suggestion page.
  3. Select List all database columns after a SELECT statement.

When you type SELECT, all column names will now be displayed in the suggestions box, listed alphabetically:

Only displaying the suggestions box manually

To turn off the automatic display of the suggestions box:

  1. On the SQL Prompt menu, select Options.
  2. On the Main > Behavior page (displayed by default when you first display the SQL Prompt Options dialog box), clear the Automatically trigger suggestions check box.

When automatic display of the suggestions box is turned off, you can press Ctrl + Space at any time to display it manually. The type of suggestions displayed will depend on where in the query you display the suggestions box.

Using categories

The suggestions box displays items grouped by category. Categories are a way of organizing suggestions so you can find the item you require more easily:

Only the categories that contain suggestions are available to select.

To switch between categories, click the All Suggestions drop-down or press Ctrl + Up arrow or Ctrl + Down arrow.

The following categories are shown:

  Tables lists tables from the current database.

  Views lists views from the current database.

  Columns lists column names, with their data types and associated table names (or table aliases). Primary key  and foreign key  columns are also shown. 
You can also use the column picker to insert columns.

 Functions lists user-defined functions in the current database, and built-in functions.

 Stored Procedures lists stored procedures from the current database.

Snippets lists shortcuts for inserting pre-defined SQL fragments or statements. 
For more information about snippets, see Inserting snippets.

 Other Suggestions lists keywords, data types, and objects such as users and roles.

Object types

You may see the following types of object or suggestion listed in Other Suggestions:

DML triggersRules

Users

Defaults
RolesUser defined types
FunctionsFull text catalogs
System variablesJoin suggestions
Linked server objects  

For SQL Server 2005 and 2008:

AssembliesQueues
Asymmetric KeysRoutes
CertificatesSchemas
ContractsServices
DDL TriggersService Bindings
Event NotificationsSymmetric Keys
Message TypesSynonyms
Partition FunctionsXML Schema Collections
Partition SchemesFull Text Stoplist (SQL Server 2008 only)

Displaying schema (owner) names

You can display schema (owner) names in the suggestions box by clicking the right arrow in the bottom left corner of the suggestions box.

The suggestions box is autmomatically widened to allow space for the schema names, shown in grey to the left of the suggestions:

To hide the list of schema (owner) names, click the left arrow  

The arrows only affect how object names are displayed in the suggestions box. The schema (owner) name is only inserted into your code when Qualify object names with owner name is selected on the Inserted Code > Qualification options page.

Changing the size of the suggestions box

You can resize the suggestions box by dragging the resize handle   The new size is remembered the next time the suggestions box is displayed.

The size of the suggestions box is remembered between sessions in SQL Server Management Studio and Visual Studio.

Moving through the list of suggestions

You can move through the list of items in the suggestions box by pressing:

  • Up / Down arrow keys to move up or down the list one item at a time. If you are at the top of the list, pressing the Up arrow key takes you to the bottom of the list; if you are at the bottom of the list, pressing the Down arrow key takes you to the top of the list.
  • Page Up or Page Down to move up or down the list one page at a time.
  • Ctrl + Page Up or Ctrl + Page Down to move up or down the list one page at a time.

Changing how suggestions are inserted

When you select an item from the suggestions box, SQL Prompt inserts the suggestion according to the options you have set in the Inserted code pages of the Options dialog box:

For example, you can specify how ALTER and INSERT statements are inserted, and whether object names are qualified. For more information, see Customizing inserted code.

Encrypted objects

SQL Prompt can automatically decrypt encrypted objects to show their creation script in the object definition box. (Available in SQL Prompt Pro Edition only.)

If you do not have permission to decrypt objects, you can still view them in the suggestions box and insert them into your query.

By default, SQL Prompt will decrypt encrypted objects. To turn this option off:

  1. On the SQL Prompt menu, select Options.
  2. Go to the Suggestions > Types of suggestion page.
  3. Turn off Decrypt encrypted objects.

Expanding SELECT * to insert all columns

When you use a * wildcard in your query, you can expand it to explicitly list all the columns in the table or view.

Press Tab after the * wildcard to insert all the columns. The columns are formatted based on the settings in the Format pages in the Options dialog box.


Didn't find what you were looking for?