How to work with SQL formatting

Schema Compare for SQL Server helps structure 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 to transform illegible SQL code into a layout that is easily readable for most users.

SQL code formatting

To format code in the entire document, do one of the following:

  • On the Text toolbar, click Format document Format Document.
  • Right-click the query and select Format Document.
  • Press Ctrl+K, Ctrl+D.

To format a certain code fragment, right-click a highlighted code fragment and select Format Selection. Alternatively, press Ctrl+K, F.

Working with SQL formatting

The tool will format the selected part of the code:

Working with SQL formatting

Outline SQL statements

A statement is outlined in the following cases:

  • It spans over two or more lines
  • It is a CREATE statement

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.

Format errors

dbForge Schema Compare can detect errors in statements during formatting. Formatting is possible only for statements that do not contain errors. The identified errors will be displayed in the Output window.

You can select to output errors in one of two ways:

  • Put syntax errors to the Output window
  • Show syntax error notification window

The errors output behavior can be configured on the Tools > Options menu. In the Options window that opens, navigate to Text Editor > Formatting > General > Notifications.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Schema Compare for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Schema Compare in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Schema Compare for your business, request a demo to see it in action.
Ready to start using dbForge Schema Compare for SQL Server?