Query Formatting

The topic describes SQL formatting features.

Query Formatting Overview

SQL Complete can help you to format your SQL statements, paying attention to case, line breaks, whitespaces, indenting, wrapping, etc. Statements with errors are skipped and are not formatted. You can tune formatting by applying a wide selection of formatting options.

Unformatted query:

Unformatted query

Formatted query:

Formatted query

The error messages appear for invalid statements when formatting the document.

Note
The Express edition of SQL Complete offers partial support of this feature. Full support is available in the Standard edition only.

Configuring Formatting Options

Before you format your code, you might want to configure formatting options and customize case formatting profiles. To tune formatting options:

  1. On the SQL Complete menu, click Options. The Options dialog box opens.
  2. On the Options dialog box, navigate to Formatting.
  3. Apply required changes.

Formatting Your Code

To format the whole code of a document do one of the following:

  1. Click Format Document on the shortcut menu.
  2. Press Ctrl+K,D.

To format a certain code fragment:

  1. Highlight a required code fragment.
  2. Click Format Selection on the shortcut menu. Alternatively, press Ctrl+K,F.

Ignoring selected code fragments

There is a possibility to format a whole SQL document in the editor ignoring selected code fragments which you do not want to be formatted. You can implement ignoring a corresponding code fragment by one of the following ways:

-- noformat
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
-- endnoformat <here any symbol types can be written>
-- noformat [symbols]
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
-- endnoformat test [symbols] <here any symbol types can be written>
-- noformat [symbols]
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department] /* endnoformat test <here any symbol types can be written> */
/* noformat [symbols] */
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department] /* endnoformat test [symbols] <here any symbol types can be written> */
/* noformat [symbols] */
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
-- endnoformat test [symbols] <here any symbol types can be written>

Noformat result

Outlining SQL Statements

The statement is outlined in the following cases:

  • it spans over two or more lines
  • it is a create statement

Nested SQL statement (for example, SELECT in CREATE VIEW) is outlined only if it starts from the new line.

Statement is not outlined if it is very short and takes only one line of code. Stored code condition and cycle operators are not outlined; the same applies to nested BEGIN … END blocks.

Semicolon Insertion

You can use SQL Complete to insert missing semicolons after each statement in a query.

To insert semicolons, go to SQL Complete menu and click the Insert Semicolons option. Alternatively, hold Ctrl and press B and then C.

Note
This feature is available in the Standard edition only.