SQL Data Compare - 9.0
Simple examples using the command line
This topic provides the following examples of how to use the command line interface:
- Comparing and synchronizing database data
Gives examples of comparison, synchronization, generating a report, specifying a comparison key, and using an existing project.
- Using a backup as a data source
Gives examples of specifying backups, multiple backups, and backup sets as a data source.
- Scheduling a comparison
Gives an example of using the Microsoft® Windows® Scheduled Task wizard to schedule a comparison.
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.
Note that:
- 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:D:\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:D:\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:D:\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:D:\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.
See also |
Was this article helpful?
SQL Data Compare
- Logging and log files
- Internal Connection Fatal Error in versions 4 and 5
- NULL textptr passed to UPDATETEXT function when running synchronization
- How much free hard disk space is required?
- Comparing the data of two tables in the same database
- Suggestions to combat comparison and synchronization performance issues
- SQL comparison and synchronization automation capabilities
- SqlNullValueException occurring in synchronization wizard
- SQL Data Compare command-line XML argument file examples
- Using Windows authentication logons between domains
- Using a filter on a column on related (joined) tables
- Determining minimum database permissions for SQL Data Compare
- Tables with compound keys may not be mapped automatically
- Best practices for synchronizing data
- Cleaning up a SQL script after SQL Compare or SQL Data Compare
- Troubleshooting System.OutOfMemoryException during comparison
- Exception thrown by db reader 1
- Reseed applying "incorrect" identity values
- Running migration scripts using SqlCmd.exe
- This SQL Server has been optimized for x concurrent queries.
- SQL Data Compare showing differences in 2 identical databases
- How to force SQL Compare and SQL Data Compare to use an Encrypted Connection
- Improving the performance of SQL Data Compare
- Logging and log files
- Case-sensitive comparisons
- Tables or views that could not be compared
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Data Compare
- Activating your products
- Activating your products
- Getting help offline
- Getting better performance out of SQL Data Compare
- Release notes - version 10.xx
- SQL Data Compare release notes - version 7.xx
- SQL Data Compare release notes - version 8xx
- SQL Data Compare release notes - version 9.xx
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Using SQL Data Compare