SQL Complete helps beautify SQL statements in a query document, managing the case, line breaks, whitespaces, indenting, wrapping, etc. according to the rules of the current formatting style.
The tool is designed is to transform illegible SQL code into a layout that is easily readable for most users.
1. In a SQL document, select a required code fragment.
2. In the shortcut menu, select Format Selection or press Ctrl+K, then Ctrl+F.
SQL Complete allows you to format a SQL script by applying different formatting profiles.
1. In a SQL document, right-click the SQL script, click Active Format Profile, and select the required format.
2. To apply the selected format profile, select the SQL document or the fragment of the code and press Ctrl+K, then Ctrl+F.
In addition, you can create a custom format profile based on the available profiles. For more information about how to create a new format profile, refer to Customize formatting styles with profiles.
There is a possibility to format an entire SQL document in the editor ignoring the selected code fragments. With noformat and endnoformat tags, you can point out where to stop formatting and where to start formatting again. Formatting can be disabled for a piece of code using one of the following ways:
-- noformat
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
-- endnoformat
-- noformat
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
/* endnoformat */
/* noformat */
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
/* endnoformat */
/* noformat */
SELECT [DepartmentID],[Name],[GroupName],[ModifiedDate] FROM [HumanResources].[Department]
-- endnoformat
A statement is outlined in the following cases:
A nested SQL statement (for example, SELECT in CREATE VIEW) is outlined only if it starts from a new line.
A statement is not outlined if it is very short and takes only one line of code. Stored code conditions and cycle operators are not outlined; the same applies to the nested BEGIN … END blocks.
SQL Complete can detect errors in statements during formatting. Only statements that contain no errors will be formatted. Meanwhile, the detected errors will be displayed in the Output window in SSMS.
You can select to output errors in one of two ways:
The errors output behavior can be configured in SQL Complete > Options > Formatting > General > Notifications.