Command-line interface

dbForge Studio for SQL Server provides a command-line interface (CLI) that enables you to automate and schedule SQL code formatting tasks without using the graphical user interface.

What you can do with the command-line interface

  • Format individual .sql files or a folder with multiple .sql files.
  • Run formatting operations in batch mode.
  • Schedule formatting operations.

Availability

The command-line interface is available in the Professional and Enterprise editions of dbForge Studio for SQL Server.

Access to the command-line interface

To run dbForge Studio CLI commands, open Command Prompt and navigate to the folder that contains dbforgesql.com. The default path to this executable depends on where dbForge Studio for SQL Server is installed. If you installed dbForge Studio:

  • As a standalone tool
C:\Program Files\Devart\dbForge Studio for SQL Server
  • As part of the dbForge Edge bundle
C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server

Command-line syntax

The /formatsql command formats SQL code in a single file or in multiple files within a folder from the command line.

dbforgesql.com /formatsql [/option_name1[:value | [parameter1:value parameter2:value ..]] /option_name2 ..]

Command-line switches

The following command enables you to view the switches available for /formatsql.

dbforgesql.com /formatsql /?

For the complete list of switches, see Command-line switches.

Example

You can format a single file using the /sourcefile switch with the /formatsql command.

dbforgesql.com /formatsql /sourcefile:"D:\NoFormat.sql" /outputfile:"D:\FormattedFile.sql"

where:

  • /sourcefile:"D:\NoFormat.sql" – The full path to the file you want to format.
  • /outputfile:"D:\FormattedFile.sql" – The full path to the formatted file.

You can format multiple files stored in a folder using the /sourcefolder switch with the /formatsql command.

dbforgesql.com /formatsql /sourcefolder:"D:\NoFormat" /outputfolder:"D:\FormattedFiles"

where:

  • /sourcefolder:"D:\NoFormat" – The full path to the folder containing the files you want to format.
  • /outputfolder:"D:\FormattedFiles" – The full path to the folder that will store the formatted files.

For detailed automation scenarios, see:

  • Automate code formatting from the command line
  • Schedule code formatting

Command-line exit codes

The /formatsql command returns exit codes that indicate the operation status.

For the complete list of exit codes, see Command-line exit codes.

Command-line wizard

dbForge Studio provides a built-in command-line wizard that helps you generate reusable command-line commands based on actions configured in the graphical user interface.

Instead of writing command-line syntax manually, you can configure formatting settings in the command-line wizard. The wizard then generates the corresponding command-line syntax, which you can review, edit, and save to a .bat file for reuse or scheduling.

Command-line wizard for SQL code formatting