ApexSQL Refactor Command Line Interface (CLI) switches

Applies to

ApexSQL Refactor

Summary

This article explains the ApexSQL Refactor CLI switches and their usage through the examples.

Description

The CLI in ApexSQL Refactor allows to format SQL scripts using one of four build-in formatting profiles or use your own customized formatting profile. Also, the obfuscation command can be used to make the SQL scripts less readable.

CLI formatting commands

/obfuscation

Executes SQL code obfuscation, making SQL code less readable

Alias: /obf

Format: /obfuscation

/formatting_script

Executes SQL script formatting (if /input_location switch is used)

Alias: /frs

Format: /formatting_script

/profile

Specifies profile for formatting. If omitted, active profile in SQL Server Management Studio will be used

Alias: /pr

Format: /profile:”profile name”

/input_location

Specifies directory location of the input scripts or a location of the single script along with script’s name

Alias: /il

Format: /input_location:”file_path\filename.sql”

/output_location

Specifies location of the output script(s) directory where the formatted script(s) will be created

Alias: /ol

Format: /output_location:”file_path”

Quick tip icon

Quick tip:

If the /output_location switch is omitted, path specified in the /input_location switch will be used as a default output destination

/output_name

Adds used formatting functionality to an existing name (e.g. formatted, obfuscated). If omitted file name of a loaded SQL script will be used

Alias: /on

Format: /output_name

Examples

Note: All examples assume that the current directory is the application directory. If not, the full path to ApexSQLRefactor.com must be specified.

To make a SQL script less readable and save it to separate location with suffix “obfuscated”, type the following:

ApexSQLRefactor /obf /il:”H:\CLI\uspGetEmployeeManagers.sql” /on /ol:”G:\ApexSQL”

The output will be like this:

Here is the code before and after obfuscation:

C:\Users\ZivkoPC\AppData\Local\Temp\SNAGHTML1139ee6.PNG

To format SQL script with desired SQL formatting profile and place formatted SQL script to specific location, type the following:

ApexSQLRefactor /frs /il:”H:\CLI\uspGetEmployeeManagers.sql” /on /ol:”G:\ApexSQL” /pr:”Compact”

The output will be like this:

To format SQL script with desired SQL formatting profile and place formatted SQL script to the same location with unformatted SQL script, type the following:

ApexSQLRefactor /frs /il:”H:\CLI\uspGetEmployeeManagers.sql” /on /pr:”Compact”

The output will be like this:

FAQ

Q: Can I format all SQL scripts from one folder at once?

A: Yes. Navigate to a folder where the SQL scripts are located using the /input_location switch, without specifying any particularly SQL script in the path.

ApexSQLRefactor /frs /il:”H:\CLI\CLI2\CLI3″ /on /pr:”Compact”

Q: Can I use the same name for the formatted SQL script as it is for the unformatted SQL script?

A: Yes, just omit the /output_name

ApexSQLRefactor /frs /il:”H:\CLI\uspGetEmployeeManagers.sql” /ol:”G:\ApexSQL” /pr:”Compact”

Additional information for common ApexSQL switches can be found on the General usage and the common Command Line Interface (CLI) switches for ApexSQL tools article