How to work with SQL formatting
Last modified: October 8, 2024
dbForge Data Generator for SQL Server helps structure SQL statements in an SQL 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.
SQL code formatting
To format code in an entire document, do one of the following:
- Click the Format Document icon
on the Text toolbar.
- Right-click the query window and select Format Document.
- Press Ctrl+K, then Ctrl+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, then F.
3. Data Generator will format the selected part of the code:
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.
Formatting errors
Data Generator 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.
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 in Tools > Options > Text Editor > Formatting > General > Notifications.
While working with formatting, you might also find useful these detailed instructions on how to customize formatting styles with profiles.
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by Data Generator for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.