ApexSQL Refactor vs. RedGate® SQL Prompt – Part 5 – Additional formatting features

In previous article ApexSQL Refactor vs RedGate® SQL Prompt – Part 4 – Additional formatting options formatting options which are found only in ApexSQL Refactor were described.

ApexSQL Refactor is a FREE SQL Server Management Studio and Visual Studio add-in which formats SQL code and SQL scripts, using nearly 200 formatting options.

In this sequel, additional formatting features, which are also found only in ApexSQL Refactor will be presented.

Impact analysis

ApexSQL Refactor highlights the changes in the preview window for both the built-in example and the current SQL query. This feature allows to preview the impact of the chosen formatting combination.

For example, the following code is typed in the query window:

SELECT firstname ,
lastname ,
title ,
phonenumber ,
passwordhash
FROM person.person
INNER JOIN person.personphone ON person.businessentityid 
= personphone.businessentityid
LEFT JOIN person.password ON person.businessentityid = password.businessentityid
WHERE lastname = 'M';

To see the impact of formatting options on this query, in the Options window, choose the Preview user’s code option, in the top right corner of the window:

Choosing the Current query option in the Formatting options dialog

For every formatting option code changes will be highlighted in the preview window. Impact of the Place joined object on new line option on a current query is shown in the picture below

Code changes are highlighted in the preview window, for every formatting option

Choosing different option will highlight the impact of the chosen option. In the picture below, the impact of the Place ON on new line option and the Place joined object on new line option is shown:

Selecting the Place ON on new line option, and adding the Place JOIN keyword at start of the line option

To see the impact of the formatting options on a built-in example, click the Preview user’s code option in the top right corner of the window, to revert back to a built-in example:

Choosing the Built-in example option from the drop down list in the preview

Apply the formatting options and see the changes. In this case, the Always use BEGIN and END in stored procedures option is checked:

Selecting the Always use BEGIN and END in Stored Procedures option

Batch formatting

The Batch formatting feature enables formatting of many SQL scripts and folders containing .sql files at once.

To use this feature, under the ApexSQL Refactor menu choose the Format SQL scripts option:

Choosing the Format SQL scripts option in the ApexSQL Refactor menu

In the Format SQL files dialog, browse to the folder where SQL scripts are saved and choose one or many .sql files for formatting:

Choosing .sql files for formatting in the Format SQL files dialog

Multiple folders or a combination of folders and SQL scripts can also be formatted simultaneously:

Formatting multiple folders simultaneously

Formatted versions of SQL files can be saved either by creating new .sql files by choosing the Create new .sql files option, or saving changes to the original .sql files using the Overwrite old .sql files option.

For batch formatting any of the pre-defined formatting options, can be used a formatting template by choosing it from the Options drop-down list.

Using the The name format for the new .sql files option, batch formatting can be personalized, which is a useful option in a multiple users environment where every user can use personal formatting template without overwriting the files of other users:

Using the The name format for the new .sql files option

See also:

ApexSQL Refactor vs RedGate® SQL Prompt – Part 1 – Common refactors compared “Encapsulate As”
ApexSQL Refactor vs RedGate® SQL Prompt – Part 2 – Additional refactors
ApexSQL Refactor vs RedGate® SQL Prompt – Part 3 – Common formatting options compared
ApexSQL Refactor vs RedGate® SQL Prompt – Part 4 – Additional formatting options

Disclaimer: All product and company names are trademarks™ or registered® trademarks of their respective holders. ApexSQL is not affiliated, associated, authorized, endorsed by, or in any way officially connected with them or any of its subsidiaries or its affiliates

 

November 21, 2013