Automatically delete a comparison report for identical databases
Last modified: March 28, 2025
When you use the command line to automate the comparison of two schemas and report generation, the report will be created regardless of whether the schemas are different or identical. However, you can configure the batch file to automatically delete the generated report if the schemas are identified as identical.
Could dbForge Schema Compare for SQL Server automatically delete a report generated when comparing two identical schemas from the command line?
Currently, it is impossible to set a job to generate a report only when there are differences in the schemas being compared. The issue is that the report will be generated even if there are no differences, resulting in an empty report in the folder.
The solution may be to create a batch file that deletes a report when identical schemas are compared.
For demo purposes, we’ll use two databases SakilaDev as a source and SakilaTest as a target on the DBFSQLSRV\SQL2022 server.
Step 1: Run schema comparison and report generation from the command line
1. Start the Command Prompt.
2. Execute the following script to compare two schemas and generate a comparison report:
"C:\Program Files\Devart\dbForge SQL Tools Professional\dbForge Schema Compare for SQL Server\schemacompare.com" /schemacompare /source connection:"Data Source=DBFSQLSRV\SQL2022;Initial Catalog=SakilaDev;Integrated Security=False;User ID=yourusername" /target connection:"Data Source=DBFSQLSRV\SQL2022;Initial Catalog=SakilaTest;Integrated Security=False;User ID=yourusername" /report:"D:\Report\report.html" /reportformat:html /includeobjects:All
This script will compare SakilaDev as a source and SakilaTest as a target. It will also generate the comparison report in an HTML format - report.html - and save it to the specified directory: D:\Report\report.html.
3. Navigate to the D:\Report\report.html folder to check whether the report was generated.
Despite the source and target databases being identical, the script still generates a comparison report.
When opening the report, you’ll see it is blank and provides no meaningful information.
Step 2: Create a batch file to delete a report for identical databases
1. In any third-party text editor, for example, Notepad or Visual Studio Code, open a new blank document and enter the following script:
Set Compare="C:\Program Files\Devart\dbForge SQL Tools Professional\dbForge Schema Compare for SQL Server\schemacompare.com"
Set ConnectionS= DBFSQLSRV\SQL2022
Set ConnectionT= DBFSQLSRV\SQL2022
Set DB1= SakilaDev
Set DB2= SakilaTest
%compare% /schemacompare /source connection:"Data Source=%ConnectionS%;Initial Catalog=%DB1%;Integrated Security=False;User ID=sourceusername; Password=sourcepassword;" /target connection:"Data Source=%ConnectionT%;Initial Catalog=%DB2%;Integrated Security=False;User ID=targetusername; Password=targetpassword;" /report:"D:\Report\report.html" /reportformat:html /sync:"D:\Report\syncfile.sql"
echo exitcode: %ERRORLEVEL%
IF %ERRORLEVEL% == 0 (echo compare complete sync file generated; GOTO end)
IF %ERRORLEVEL% == 100 (del "D:\Report\report.html")
:end
pause
When comparing identical source and target databases, the script will return exit code 100. In this case, the report will be deleted automatically.
Conversely, exit code 0 signifies the successful completion of the schema comparison operation without errors. In such cases, the script generates and stores the report and synchronization file in the specified folders. For a complete list of exit codes used in the command line, see Exit codes used in the command line.
Note
The Set Compare command specifies a default installation path for dbForge Schema Compare for SQL Server. Depending on how you installed the tool, the path varies:
If it has been installed as a part of dbForge SQL Tools, the installation path will be - C:\Program Files\Devart\dbForge SQL Tools Professional\dbForge Schema Compare for SQL Server\schemacompare.com.
If it has been installed as a part of Compare Bundle for SQL Server, the installation path will be - C:\Program Files\Devart\Compare Bundle for SQL Server\dbForge Schema Compare for SQL Server\schemacompare.com.
If you have changed the path, specify the correct path to the schemacompare.com file.
2. Replace the following data with your actual parameters:
Parameter | Description |
---|---|
DBFSQLSRV\SQL2022 | Name of the source and target server |
SakilaDev | Name of the source database |
SakilaTest | Name of the target database |
sourceusername and sourcepassword | Source user credentials |
targetusername and targetpassword | Target user credentials |
D:\report_file.html | Path to the report |
D:\Report\syncfile.sql | Path to the synchronization file |
3. Save the file with the .bat extension.
Step 3: Execute the batch file to delete the report
1. Navigate to the file location and double-click the file to execute it.
2. The script returns exit code 100, meaning it deleted the report because the two databases you compare are identical.
You can also schedule the task to delete a comparison report for identical databases using the Windows Task Scheduler. When done, the computer will perform the task automatically according to the schedule. For more information, see the Schedule database synchronization topic.
Explore more
Configure the schema comparison logs email delivery
Discover how to configure automatic email delivery of the log file for both successful and failed SQL schema comparisons.
Compare schemas in multiple databases from the command line
Find out how to automatically automate and schedule the daily comparison and synchronization of multiple databases using the command line.
How to set up automatic log sending in the event of a comparison error
Learn how to configure the automatic email delivery of the schema comparison log file specifically for cases where the comparison encounters failures.
How to automatically track database schema changes
Learn how to trace database schema changes automatically with the help of PowerShell scripts.
Automate schema comparisons with PowerShell
Learn how to set up an automated process for schema comparison between a local scripts folder and a remote database.
Commit database schema changes to a Git repository automatically
Learn how to automate database schema changes in version control systems like Git.
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by Schema Compare for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.