The topic describes SQL formatting features.
dbForge Studio for SQL Server 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:
Formatted query:
The error messages appear for invalid statements when formatting the document.
Note
The Express edition of dbForge Studio for SQL Server offers partial support of this feature. Full support is available in the Standard edition only.
Before you format your code, you might want to configure formatting options and customize case formatting profiles. To tune formatting options:
To format the whole code of a document do one of the following:
To format a certain code fragment:
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>
The statement is outlined in the following cases:
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.
You can use dbForge Studio for SQL Server to insert missing semicolons after each statement in a query.
To insert semicolons, right-click the SQL document body to call the context menu. Go to Refactoring and click the Insert Semicolons option. Alternatively, hold Ctrl and press B and then C.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!