Handle SQL formatting

dbForge Studio for SQL Server helps you format SQL statements by managing case, line breaks, whitespace, indentation, wrapping, and more, in accordance with the current formatting style rules. As a result, you can get a SQL code layout that is easily readable for most users.

Note

dbForge Studio can format only complete code blocks. Applying formatting to a code fragment (for example, a part of a query or a single line of code) will result in a syntax error.

Format SQL code

You can format code for an entire document or its fragment.

  • To format code for an entire document, click The Format Document icon on the Text toolbar.

    Alternatively, press Ctrl+K, D.

  • To format a code fragment:

    1. Select the code fragment.

    2. Right-click the selected code.

    3. Select Format > Format Selection.

    Alternatively, select the code fragment and press Ctrl+K, F.

The formatting applies according to the settings of the active formatting profile. For more information, see Customize the formatting style with profiles.

For more information on formatting settings, see Formatting options.

Disable formatting for a code fragment

When formatting an entire SQL document in the editor, you can exclude specific code fragments from formatting by wrapping them with the noformat and endnoformat tags.

Any of the following formats is acceptable.

-- noformat
<code>
-- endnoformat
-- noformat
<code>
/* endnoformat */
/* noformat */
<code>
/* endnoformat */
/* noformat */
<code>
-- endnoformat 

Formatting errors

dbForge Studio can detect errors in statements during formatting. If you have a formatting error and attempt to format the code, an error message is displayed.

A message about syntax errors

Warning

Only the valid statements can be formatted. Statements with errors cannot be formatted.

Tip

Select the Don’t show this message again checkbox to prevent the error message from appearing when formatting errors are detected.

You can view the detected errors:

  • In the Output window by selecting View > Output.
  • In the Error List window by selecting View > Error List.