dbForge Schema Compare supports a command-line interface, which means that you can automate schema comparison and synchronization operations through the command line.
Note
To run the Command Line in Windows 11:
From the Windows taskbar
- Right-click the taskbar at the bottom of the screen and then select Run. or
- Click Start or press the Windows key on your keyboard to open the Start menu.
- Type cmd or Command Prompt in the search bar.
- Select the Command Prompt app from the search results to open it.
Using shortcut keys
- Press the Windows + R keys, to show the Run command window.
- In the window that opens, type cmd and press Enter.
To access the dbForge Schema Compare for SQL functionality from the command line, you need to navigate to the schemacompare.com file, located in the tool’s installation folder on your PC. For example:
cd C:\Program Files\Devart\Compare Bundle for SQL Server\dbForge Schema Compare for SQL Server
To see a quick help on the arguments available in the command line, type the following:
schemacompare.com /?
To get detailed information about each command-line operation, execute the following command and specify the desired option value schemacompare /option_name /?
. For example, schemacompare /backup /?
.
You can interact with dbForge Schema Compare for SQL via the command line in three ways:
1. Enter all the arguments directly in the Command Prompt. For example:
/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"
2. Specify the path to the comparison document you’ve saved previously. This uses both the connection and comparison settings defined in the document.
/schemacompare /compfile:"D:\file_name.scomp"
If you need to use parameters not specified in the file, add them in the Command Prompt. For example:
/schemacompare /compfile:"D:\file_name.scomp" /report:"report.txt"
3. Enter the path to a file containing the required command-line arguments. For instructions on how to prepare the file, see the information provided below. For example:
/argfile:"D:\file_name.txt"
If you need to use parameters not specified in the file, add them in the Command Prompt. For example:
C:\Program Files\Devart\Compare Bundle for SQL Server\dbForge Schema Compare for SQL>schemacompare.com /schemacompare /argfile:file_name.txt /sync
To create a .txt file with command-line arguments for Schema Compare, you have two options: manually create the file or automatically generate it from the Schema Compare GUI.
1. Open a text editor, such as Notepad in Windows.
2. Enter your command-line arguments into the editor. These should mirror the syntax you’d use in the command prompt, including all necessary parameters for your schema comparison task.
3. Save the file with a clear name and a .txt extension.
To generate a .txt file with command-line arguments automatically:
1. Open the Schema Comparison wizard using one of the following ways:
2. On the Source and Target page of the wizard, select the source and target data sources you want to compare.
3. Optional: You can go through other wizard pages to configure the data comparison.
4. On the Options page, click Save settings to a command line arguments file in the upper right corner. In the Save As window that opens, specify the file name and location to save the file and then click Save.
The selected Source and Target connection strings along with comparison options will be saved as a .txt file with command-line arguments. You can edit the values of comparison options in the file as described in Options used in the command line.
Note
The generated file will not contain password information for security purposes. You should edit the file and enter the passwords manually.
A .bat file is a type of script file used to automate tasks on Windows operating systems. It contains a series of commands that the Windows Command Prompt can execute sequentially. You can create a .bat file containing the Schema Compare commands right from the tool’s GUI.
1. Open the Schema Comparison wizard using one of the following ways:
2. On the Source and Target page of the wizard, select the source and target data sources you want to compare.
3. Optional: You can go through other wizard pages to configure the data comparison.
4. On the Options page, click to open the Save dropdown in the lower left corner. Then select Save Command Line.
5. In the Command line execution file settings dialog that opens, review the automatically generated settings and modify them if required. To validate the generated command line, click Validate. Once done, click Save.
6. Specify the file name and location to save the file and then click Save.
When using dbForge Schema Compare from the command line, you can configure the tool to automatically append the current timestamp to the names of output files, such as reports or logs. This ensures each file has a unique name based on its creation time, simplifying file organization and identification.
1. Add the following command to the .bat file with the Schema Compare arguments.
SET TimeStamp=%date:~6,4%-%date:~3,2%-%date:~0,2%-0%time:~1,1%-%time:~3,2%-%time:~6,2%
This command generates a timestamp string from the current system date and time, then assigns it to a variable named TimeStamp.
2. Add a variable to the output files names. For example: Log_File%TimeStamp%.log
or Update_Script%TimeStamp%.sql
.
The whole script might look as follows:
SET TimeStamp=%date:~6,4%-%date:~3,2%-%date:~0,2%-0%time:~1,1%-%time:~3,2%-%time:~6,2%
"C:\Program Files\Devart\Compare Bundle for SQL Server\dbForge Schema Compare for SQL\schemacompare.com" /schemacompare /source connection:"User Id=yourUsername;Host=demo\SQLEXPRESS;Database=AdventureWorks2022;Character Set=utf8" /target connection:"User Id=yourUsername;Host=demo\SQLEXPRESS01;Database=AdventureWorks2022;Character Set=utf8" /log:"D:\Log_File_%TimeStamp%.log" /sync:"Update_Script_%TimeStamp%.sql"
Perform schema comparison using the settings specified in the .scomp file:
/schemacompare /compfile:"D:\file_name.scomp"
Perform a schema comparison using the command-line arguments specified in the file_name.txt file.
/schemacompare /argfile:"D:\file_name.txt"
Compare databases using the provided connection details:
schemacompare.com /schemacompare /source connection:"user Id=yourUsername;password=yourPassword;host=your_host;Character Set=utf8;port=3306;database=database_name" /target connection:"user Id=yourUsername;host=your_host;Character Set=utf8;port=3306;database=database_name;password=yourPassword
Perform schema comparison using the command-line arguments specified in the file_name.txt file and save the log output to the specified file:
/schemacompare /argfile:"D:\file_name.txt" /log:"C:\MyLog.log"
Perform schema comparison using the settings specified in the .scomp file and save the comparison report to the specified HTML file:
/schemacompare /compfile:"D:\file_name.scomp" /report:"C:\Report.html"
Perform schema comparison and synchronization using the command-line arguments specified in the file_name.txt file:
/schemacompare /argfile:"D:\file_name.txt" /sync
Perform schema comparison using the command-line arguments specified in the file_name.txt file and save a synchronization script:
/schemacompare /argfile:"D:\file_name.txt" /sync:"C:\sync_script_name.sql"