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_script 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: /pf

Format: /profile:”profile name”

/input_script

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

Alias: /is

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

/output_script

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

Alias: /os

Format: /output_script:”file_path”

Quick tip icon

Quick tip:

If the /output_script switch is omitted, path specified in the /input_script 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 /is:”H:\CLI\uspGetEmployeeManagers.sql” /on /os:”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 /is:”H:\CLI\uspGetEmployeeManagers.sql” /on /os:”G:\ApexSQL” /pf:”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 /is:”H:\CLI\uspGetEmployeeManagers.sql” /on /pf:”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_script switch, without specifying any particularly SQL script in the path.

ApexSQLRefactor /frs /is:”H:\CLI\CLI2\CLI3″ /on /pf:”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 /is:”H:\CLI\uspGetEmployeeManagers.sql” /os:”G:\ApexSQL” /pf:”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