SQL Prompt 9

Working with SQL Code Formatting and Styles (Quick Ref)

When I format my code, SQL Prompt changes it too, such as by adding semicolons. Why?

When you run Format SQL, SQL Prompt will apply all the style options defined for the active style, plus any of the refactoring actions that are currently enabled to run as part of this command.

From the Prompt menu, select Options, and navigate to the Format | Styles section, and you can select which actions will run automatically, as part of Format SQL.

Format your SQL code

Running the Format SQL command will format your SQL according to the current active style. In a query window do one of the following:

  • on the SQL Prompt menu, click Format SQL
  • right-click in your query window and click Format SQL
  • press Ctrl + K then Ctrl + Y

If you only want to format a fragment of your SQL script, first highlight the fragment in the query window, and then run Format SQL. In this case, you can also choose Format SQL from the Actions list.

Create a new style

  1. Use Edit formatting styles from the SQL Prompt menu
    1. Under Your Styles, click + Create a Style, name the style and specify the style on which it will be based or choose Copy… from the vertical ellipsis next to an existing style
    2. Under Redgate styles, choose Copy… as above, or simply double click on a style
  2. Edit the Style options in the left-hand pane to control the layout and formatting of the various statement, clauses, and expressions that comprise a typical SQL command.

Modify a style

  1. Use Edit formatting styles from the SQL Prompt menu
  2. Under Your Styles, choose Edit… from the vertical ellipsis next to an existing style
  3. Edit the Style Options in the left-hand pane

Set a preferred style

Out of the box, SQL Prompt's built-in Default style will be the active style, so just 'Kick Yourself' to try it out. To set a different style as the "default":

  1. Use Edit formatting styles from the SQL Prompt menu
  2. Choose Set as Active… from the vertical ellipsis next to an existing style

Select a style to apply

  • Select the style from Active Style in the Prompt Options menu, or from the right-click context menu, within in a query window

Exclude a block of code from being formatted

  • Highlight a line or block of code and select the Disable formatting for selected text action from the Actions List.

Remove all formatting from a selected block of code

  • Highlight a line or block of code and select Unformat from the Actions list. This will remove all formatting whitespace from the selected code.

Formatting and Refactoring Keyboard Shortcuts

ActionShortcut
Format SQLCtrl+K, Ctrl+Y
Apply Casing OptionsCtrl+B,Ctrl+U
Qualify Object NamesCtrl+B,Ctrl+Q
Expand WildcardsCtrl+B,Ctrl+W
Insert SemicolonsCtrl+B,Ctrl+C
Add/Remove Square BracketsCtrl+B,Ctrl+B
Inline Stored ProcedureCtrl+B,Ctrl+I
Encapsulate as new stored procedureCtrl+B,Ctrl+E
Rename Scripted ObjectF2 (Shift+F2 in Visual Studio)

Didn't find what you were looking for?