SQL Prompt - 5.3
Using SQL Prompt to speed up your queries: examples
The following examples show how SQL Prompt can help you to write queries more quickly. All these examples use the Adventure Works database for SQL Server 2005.
Example 1: Writing a simple query
- In your query editor, start a new query on the AdventureWorks database.
- Type:
se(press Tab)* frAs you type, the suggestions box is displayed. Whenever you press the Tab key, SQL Prompt inserts the currently highlighted suggestion into the query:

Press Tab, then the Space bar, then type:
pThe suggestions box shows all relevant suggestions beginning with p :

Note: SQL Prompt always places the most contextually relevant types of suggestions at the top of the list, depending on what you have typed in your query.
- Press the Down arrow key once to highlight the ProductCategory table.
You can check if this is the correct table by looking at the column names and data types in the object definition box:
- Press Enter to insert the table and complete the query. Your query should now look like this:

Note that in SQL Server 2005 and 2008, SQL Prompt automatically inserts the schema name for objects in non-default schemas.
Quick tips:
- Use the Up and Down arrow keys to move through the list of suggestions.
- Press Tab or Enter to insert the current suggestion. To set other insertion keys, for example Space bar or Dot (.), see Setting main behavior options.
- To view the object creation script for an object instead of a summary, click the Script tab in the object definition box. The Script tab will be the default view from this point onwards.
- To turn off the automatic display of the object definition box, see Using the object definition box.
- Note that SQL Prompt automatically replaces lower case keywords with upper case as you type. You can change the case used for keywords. See Options for formatting your code.
- You can also change how object names are qualified when inserted into your code. See Inserting suggestions into your code.
Example 2: Using the Column Picker to select and insert columns
In this example, the Space bar is used as an additional insertion key. To define the Space bar as an insertion key:
- On the SQL Prompt menu, select Options, then
- In the Options dialog box, go to the Main > Behavior page, then under Insertion Keys, select Space bar, then click OK.
From now on, each time you press the Space bar, the currently highlighted suggestion will be inserted into your query.
- Create a new query and type:
se * fr cus(include all the spaces)then press Enter.
SQL Prompt will insert the matching suggestion whenever you press the Space bar, so your query should now look like this:

Note: you can move the cursor to just after the * and press Tab to insert all columns:

- To insert specific columns from the CUSTOMER table, rather than all the columns, move the cursor to just after the * and click the Backspace button to delete *.
- Press Ctrl + Space to display the suggestions box.
- Press Ctrl + Left arrow to show the Column Picker:

The column picker allows you to choose multiple columns from the table. Primary key
and foreign key
columns are indicated by key icons.
- Use the Up and Down arrow keys to move throught the list, then press the Space bar to select a column for insertion. You can also use the mouse to select the check box for each column to be inserted:

- Press Enter to insert all the columns into your query. Your query should now look like this:

Columns are inserted in the order in which they were selected; and automatically formatted based on the options set in the Format pages of the SQL Prompt Options dialog box.
Quick tips:
- By default, columns are listed in alphabetical order. To list them in the order they are defined in the table, select List in table order. When inserting columns from more than one table, List in table order groups columns by table rather than in a single alphabetical list.
- When the Column Picker is displayed, type the first few letters of a column name to filter the list. Any columns already selected are displayed at the bottom of the list and will still be inserted.
- Clicking Select All toggles between selecting all columns and selecting none.
- You can change how SQL Prompt lays out the inserted code (for example, to place each column on a new line). See Formatting your code.
- The first time you display the column picker, a callout message box appears; click X to close it. Once you close it, the tooltip will not reappear.
Example 3: Using a snippet to insert a block of code
- Create a new query and type
sThe suggestions box shows all suggestions that start with s.
- Press Ctrl + Down arrow twice to change the category of suggestions to Snippets.
- Press the Down arrow key to move down the list of snippets to highlight
ssf.
- Press any of the insertion keys (for example Space bar, Tab or Enter) to insert the snippet code. The position of the cursor after the snippet has been inserted is specified as part of the snippet definition.

Quick tips:
- Use Ctrl + Down to change the category of suggestion (for example, to see only views or stored procedures in the suggestions box).
- To make a snippet from a block of code in your editor, highlight it, then right-click and select Make Snippet.
- SQL Prompt is pre-configured with a large number of default snippets. To see a list of all snippets, and to edit, delete or create new snippets, on the SQL Prompt menu, select Snippet Manager.
For more information on snippets, see Managing snippets.
Example 4: Writing a full INSERT statement
- Create a new query and type
ii. - This is a snippet; Press Tab to expand it to an
INSERT INTOstatement and press the Space bar to display the suggestions box again:
- Type
custo filter the list to the two customer tables, then press Enter to insert the first (highlighted) table:Customer.SQL Prompt completes the syntax of the
INSERTstatement, and inserts the name, data type, and default value for each column as comments:
The insertion point is positioned for you to insert the values.
Quick tips:
- By default, column names, data types and default values are automatically inserted when you write an
INSERTstatement. You can turn off some or all of these defaults using the SQL Prompt options dialog. See Customizing inserted code. - To see a list of columns in a table, and their data type, move the mouse pointer over a table name to display the tooltip, then click the tooltip:

The object definition box is displayed, showing the summary for the object. If the Script tab is displayed instead, click Summary:

Example 5: Executing functions and stored procedures
- Create a new query and type
EXEC - Press the Space bar.
The suggestions box is displayed, with all the functions and stored procedures at the top of the list. Select a function in the list, then click the Script tab to see a preview of the object creation SQL script in the object definition box for the selected object.

Note: You can click the Summary tab in the object definition box to view a list of parameters for that function:

- Press Enter to insert the function into your code:

Quick tips:
- By default, parameters are automatically inserted into functions and stored procedures, and the data type and default value is displayed for each paramater. You can change this behavior in the SQL Prompt Options dialog box. See Customizing inserted code for more details.
- To see only stored procedures in the suggestions box, click the All Suggestions tab at the bottom of the suggestions box, then click Stored Procedures:

- To view system functions and stored procedures in the suggestions box, select List system objects on the Suggestions > Types of suggestion page in the SQL Prompt Options dialog box.
Example 6: Writing a cross-database query
Cross-database queries are automatically supported in SQL Prompt. You do not need to select an option to enable them.
- Create a new query on the AdventureWorks database.
- Type
SELECT * FROM pub - SQL Prompt lists the pubs database as a matching suggestion:

- Press Tab to insert the database name into your query, then type
.(Dot). As soon as you press Dot, SQL Prompt reads all the database objects from the pubs database. For large databases, this may take a few minutes. - If you do not have permissions to connect to that database, or to access some objects in the database, a warning dialog is displayed:

Note: This warning may also be displayed if SQL Prompt has run out of memory to store the objects from this database.
See Managing connections and memory.
Was this article helpful?
SQL Prompt
- SSMS failed to load SQL Prompt add-in 80070002
- No SQL Prompt menu appears in Query Analyzer
- SQL Prompt is showing an old version of my stored procedure (version 3)
- Removing menu items after uninstalling SQL Prompt and SQL Refactor
- A newly-created table exists, but it is not visible in the candidate list (version 3)
- Configuring permissions for SQL Prompt
- Using Intellisense or auto complete with a VS Web project (version 3.5)
- Uninstalling the Visual Studio 2005 add-in
- Unable to cast object of type 'System.DBNull' to type 'System.String' (version 3)
- Suggestions to improve performance for pre-formatted SQL (version 3.9)
- Changing the location of the settings, cache files and snippets folders
- Saving SQL Prompt options (version 3)
- SQL 2008 installation fails with Express Tools rule (version 3.8)
- Add-in failing to load into SQL Server Management Studio on Vista
- Removing SQL Server Management Studio Integration after uninstallation
- Layout SQL Error
- Downgrading to SQL prompt 3.9 from 4.0
- Candidate suggestions being displayed slowly
- SQL Prompt is not showing all linked servers
- Log files
- Refreshing the cache
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Prompt
- Activating your products
- Activating your products
- Getting help offline
- Customizing SQL Prompt to write SQL code more efficiently
- SQL Prompt 3.xx - reducing memory usage to improve performance
- Using SQL Prompt 4: tips for SQL Prompt 3 users
- SQL Prompt release notes - version 4.xx
- Release notes - version 5.xx
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Using SQL Prompt