Automate schema comparison and synchronization from the command line

The /schemacompare command lets you run schema comparison from the command line.

Note

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

Syntax

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

Get command-line help

To view the list of switches available for /schemacompare, run the following command:

dbforgesql.com /schemacompare /?

Command details

  • 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"
    
  • To enter all arguments, use one of these options:

    • Type all the arguments directly in the Command Prompt.
    dbforgesql.com /schemacompare /source connection:"Data Source=<server_name>;Initial Catalog=<catalog>;Integrated Security=False;User ID=yourUsername" /target connection:"Data Source=<server_name>;Initial Catalog=<catalog>;Integrated Security=False;User ID=yourUsername"
    
    • Specify a path to a previously generated .txt file with required command-line arguments by using the /argfile command.
    /argfile:"D:\file_name.txt"
    
    • Specify a path to the schema comparison document (.scomp) with the source and target connection strings and comparison options by using the /compfile command.
    /compfile:"C:\MyComparison.scomp"
    
  • To generate and save a log file, specify the file name and location in the /log command.

/log:"C:\LogFile.log"
  • To generate and save a comparison report file, specify the file name and location in the /report command.
/report:"C:\Report.html"
  • To synchronize the schemas and generate a synchronization script, specify the file location and name in the /sync command.
/sync:"C:\sync_script.sql"

Create a file with command-line arguments

You can generate a .txt file with command-line arguments in the New Schema Comparison wizard or create a .bat file containing commands to be executed by the Command Prompt sequentially from the command-line wizard.

Examples

Compare databases using settings from a file saved earlier

This command runs a comparison with predefined settings stored in the .scomp file without requiring you to specify parameters directly in the command line.

dbforgesql /schemacompare /compfile:"D:\workDir\SC1vsSC2.scomp"

Compare databases and save a synchronization script to a .sql file

This command compares the schema of db1 on SqlServer1 with db2 on SqlServer2 and generates a SQL synchronization script containing the SQL statements required to update the target database so that it matches the source database.

dbforgesql /schemacompare /source server:SqlServer1 user:sa password:sa database:db1 /target server:SqlServer2 user:sa password:sa database:db2 /sync:"D:\compare_result.sql"

Compare and synchronize databases using a .scomp project file

This command performs a schema comparison using the settings stored in the .scomp project file, applies several comparison options, generates an HTML report, and then synchronizes the target with the source.

dbforgesql /schemacompare /compfile:"file_name.scomp" /icase:yes /IgnoreForeignKeys:yes /report:"report.html" /reportformat:HTML /groupby:objecttype /incsettings:T /sync

Write logs during database comparison

This command performs a schema comparison based on a saved project file (.scomp) and records the full execution log to D:\log_file.log.

dbforgesql /schemacompare /compfile:"file_name.scomp" /log:"D:\log_file.log"