Formatting your code
Published 24 April 2017
To format your SQL code, 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
This will format your SQL according to the current active style.
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.
Customize your formatting style
A formatting style is a saved set of options for how to lay out your SQL. To create or edit a formatting style, on the SQL Prompt menu, click Edit Formatting Styles.
SQL Prompt includes some Redgate styles that you can use as a starting point for your own style:
To create your own style, under YOUR STYLES, click + Create a style.
Your active style is the formatting style that is applied when you run Format SQL, and is marked with . To make a style active, make sure it is selected and click Set as active.
Old formatting styles
Styles created before SQL Prompt 8 will be imported automatically. These will appear under YOUR STYLES and have the suffix (old).
Note: SQL Prompt 8 includes new formatting options, so old styles might have changed after being imported.
To edit a style, make sure it is selected and click Edit style. SQL Prompt includes options for formatting DML statements, DDL statements, CASE statements, JOINs, CTEs, and more:
Disable formatting for blocks of code
You can disable SQL Prompt formatting for certain blocks of code in a query:
- In a query window, select the code you don't want SQL Prompt to format, and click Ctrl to open the actions list.
- Type di and select Disable formatting for selected text:
SQL Prompt encloses the selected code within comments:
This code now won't be formatted when you run Format SQL.
If SQL Prompt wasn't able to format your code, a pop-up window will be displayed showing the reasons: