Altova DatabaseSpy 2023 Enterprise Edition

Formatting SQL

Home Prev Top Next

Most database versions support SQL code formatting in SQL Editor. For all such databases, the SQL code formatting preferences can be customized. You can also disable formatting for the SQL Editor and the Database Structure Change Script window. By default, SQL formatting is enabled in these two windows.

 

Any changes you make to the default formatting are recorded in a configuration file, at the following path: ..\Documents\Altova\DatabaseSpy2023\SQLFormattingConfigurations.qfmt. Note that the configuration file is not automatically transferred during upgrades if the installation folder changes. After upgrading to a new major version, you have to copy the configuration file to the new installation folder (..\Documents\Altova\DatabaseSpy<Version>) yourself.

 

Note:Configurations that have been saved in DatabaseSpy 2009 or later cannot be opened in earlier releases.

 

The formatting is applied automatically when you generate SQL. To apply formatting on demand, first click inside the SQL Editor, and then do one of the following:

 

Click the Apply SQL Formatting to the active SQL Editor ic_apply-sql-formatting button.

On the SQL Refactoring menu, select Format SQL.

 

To customize the formatting preferences for a specific database kind:

 

1.On the Tools menu, click Options. (Alternatively, press Ctrl+Alt+O.)

2.Go to SQL Editor | Formatting settings page.

3.Click SQL Formatting Configurations. The SQL Formatting Configurations dialog box opens.

4.Select the database kind from the Configurations list and then change your preferences as required.

 

The SQL Formatting Configurations dialog box displays a tree structure where you can define preferences on root level or specify more specific options for individual statement types. The Preview area is updated immediately to reflect any changes you make.

ds_dlg_sql_formatting

 

Options on root level

At the root level, you can either deactivate the formatting options for a specific database type (without deactivating the SQL formatting feature as a whole), or define general formatting options which may affect all statements.

To deactivate SQL formatting for a certain database kind:

1.Select the menu command Tools | Options or press Ctrl+Alt+O to open the Options dialog box.

2.Click SQL Formatting Configurations.

3.In the SQL Formatting Configurations dialog box, select the respective database kind from the Configurations list.

4.In the Options section, select the Ignore All check box.

 

Options for the individual statement types

When you select one of the statement types in the tree structure, the corresponding formatting options are displayed in the window on the right side of the dialog box. Different options are available for the individual statement types.

 

The header of the options list provides an icon on the right edge that displays the properties inherited from the root level. If you click the Show inherited properties ic_show-inherited-properties icon, the options from the root level are displayed and you can change the settings for the selected statement type. Note that these changes apply only to the selected statement type; for all other parts of the statements, the settings defined on the root level are still valid! Options that differ from those defined on root level appear in bold type. These options remain also visible if you click the Hide inherited properties ic_hide-inherited-properties button.

 

You can customize the display of the following statement types (click a statement type to view the formatting options applicable to it):

 

Select

Create Table

Create Function

Alter Table

Alter Function

Update

Insert

Create Procedure

Create Trigger

Alter Procedure

Create View

Alter View

 

Note:Some statement types listed above are not available for configuration if they are not applicable to the selected database kind.

 

Restoring the default settings

You can reset your custom formatting preferences for any database kind to the default settings as follows:

 

1.In the SQL Formatting Configurations dialog box, select the respective database kind from the Configurations list.

2.Click Reset.

 

Removing formatting and comments

You can remove all additional whitespace and line feeds that have been added by the Format SQL command. The menu command SQL Refactoring | Remove Comments and Formatting not only deletes all these characters but also removes any text that is located between block comments or after line comments.

sql_format-flatten

The left pane shows a SELECT statement when SQL formatting is enabled in the SQL Formatting options and the Whitespace markers and End-of-Line markers options are activated in the Text View Settings. The right pane shows the same statement with the same options after the Remove Comments and Formatting command has been selected.

 

Removing comments

If you want to get rid of all that text in your statement that has been commented out, select the Remove comments command in the SQL Refactoring menu. Any text that is enclosed by block comment characters or appears after a line comment will be deleted from the active SQL Editor window.

sql_remove-comments

© 2017-2023 Altova GmbH