SQL Data Compare 15

Simple examples using the command line

This page provides the following examples of how to use the command line interface:

For detailed examples of how to include specific tables, see:

Comparing and deploying database data

To compare the data in WidgetDev and WidgetLive on the local instance:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive

To compare the data in WidgetDev and WidgetLive, and export the differences to .csv files:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive\\   
/Export:"D:\SQLDataCompareReports"

To compare the data in WidgetDev and WidgetLive, and deploy the databases by updating WidgetLive:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive
     /sync

To compare the data in WidgetDev and WidgetLive, specifying the comparison key for the Widgets table explicitly to be PK_Widgets:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive
     /ComparisonKeys:Widgets:PK_Widgets

Note that you can specify a primary key or a unique index as the comparison key when you use the command line interface.

To use a project that you have previously created using the graphical user interface:

sqldatacompare /Project:"C:\SQLDataCompare\Projects\Widgets.sdc"

When you use a project, all tables and views that were selected for comparison when the project was saved are automatically included.

  • you cannot use /project with /include or /exclude
  • all project configuration details - such as column settings, custom comparison keys, and WHERE clauses - are applied when you use /project
  • the project configuration does not include table and row selections for the comparison results
  • the command line cannot back up databases before deployment
    If the project includes backup settings that have been set up using the deployment Wizard, those settings are ignored.

To deploy data in WidgetDev and WidgetLive, specifying that for table WidgetPrices only columns RecordID, Price, and Active are to be migrated:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive\\     /IncludeColumns:WidgetPrices:RecordID,Price,Active
     /sync

Using a backup as a data source

To compare a backup of WidgetDev with WidgetLive:

sqldatacompare /Backup1:"D:\MSSQL\BACKUP\WidgetDev_20080807_143235.sqb" /db2:WidgetLive

If you are comparing a backup set that contains multiple files, use the /backupset1 switch to specify the files which make up the first backup set, and use the /backupset2 switches to specify the files which make up the second:

sqldatacompare /Backup1:"D:\MSSQL\BACKUP\WidgetDev.bak" /Backupset1:"2008-09-23 Full Backup" /db2:WidgetLive

If the backup set switches are not specified, SQL Data Compare uses the latest backup set.

To specify more than one backup file, separate the file names using semicolons:

sqldatacompare /Backup1:"D:\WidgetDev_Full.bak";"D:\WidgetDev_Diff.bak" /db2:WidgetDevelopment

For encrypted backups that have been created using SQL Backup, use the /BackupPasswords1 and /BackupPasswords2 switches to specify the passwords; when there is more than one backup password, separate the passwords using semicolons.

sqldatacompare /Backup1:"D:\MSSQL\BACKUP\WidgetDev.sqb" /BackupPasswords1:Pa$$w0rd /db2:WidgetLive

If you are comparing a differential backup, you must also specify the associated full backup.

For more information, see Working with backups.

Scheduling a comparison

You can use the Microsoft Windows Scheduled Task wizard to schedule a comparison by creating a script to run the comparison.

For example, to compare the data in two databases, you could create the following script:

C:
cd path_to_installation_folder
sqldatacompare /db1:FirstDatabaseName
/db2:SecondDatabaseName >> log_file

where:

  • path_to_installation_folder is the path to the folder in which you installed the tool. Alternatively, you can add the installation folder to your PATH environment variable and omit this line.
  • FirstDatabaseName and SecondDatabaseName are the names of the databases that you want to compare.
  • log_file is the full path to the log file. For example, C:\SQLCmdLine\Log.txt

In this example MS-DOS batch scripting is used, a basic scripting language that is supported on all versions of Windows. If preferred, you could use VBScript, JScript, PHP, Perl, Python or any other scripting language of your choice.

Save the script as a .bat file. You can then specify the .bat file as the program to run from within the Scheduled Task wizard by browsing to it.


Didn't find what you were looking for?