SQL Data Compare 8

Simple examples using the command line

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

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

Comparing and synchronizing 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 synchronize the databases by updating WidgetLive:

sqldatacompare /Database1:WidgetDev /Database2:WidgetLive
     /Synchronize

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 synchronization
    If the project includes backup settings that have been set up using the Synchronization wizard, those settings are ignored.

To synchronize 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
     /Synchronize

Using a backup as a data source

To compare a backup of WidgetDev with WidgetLive:

sqldatacompare
     /Backup1(big grin):\MSSQL\BACKUP\WidgetDev_20080807_143235.sqb
     /db2:WidgetLive

If you are using native SQL Server backups and the backup files contain multiple backup sets, use the /Backupset1 and /Backupset2 switches to specify the required backup set. If the backup set switches are not specified, SQL Data Compare uses the latest backup set.

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

To specify more than one backup file, the file names are separated using semicolons.

sqldatacompare /Backup1(big grin):\MSSQL\BACKUP\WidgetDev_Full.bak
           D:\MSSQL\BACKUP\WidgetDev_Diff.bak /db2:WidgetLive

For encrypted backups that have been created using SQL Backup, use the /Password1 and /Password2 switches to specify the passwords; when there is more than one password, the passwords are separated using semicolons.

sqldatacompare /Backup1(big grin):\MSSQL\BACKUP\WidgetDev.sqb
     /Password1:Pa$$w0rd /db2:WidgetLive

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?