SQL Data Compare - 9.0
Deploying a database from source control
This topic provides a simple example of using the SQL Compare and SQL Data Compare command line interfaces to deploy a database from source control.
In this example, changes have been made to the schema and data of the database WidgetDev. These changes must be deployed to the testing database WidgetTest.
The latest version of WidgetDev is maintained in source control as the scripts folder WidgetScripts.
The changes are deployed by using SQL Compare and then SQL Data Compare to synchronize WidgetTest (the target) with WidgetScripts (the source).
For more information, see
Before we can deploy, we must get the latest version of WidgetScripts from source control. In this example, the latest version is updated to the working folder C:\Scripts\WidgetScripts
We will deploy all changes to the database schema, and changes to only the static data. The transactional data in the table WidgetPurchases will not be modified.
Note that:
- Scripts folders and the command line interface are only available with the SQL Compare and SQL Data Compare Professional Editions.
- Schema synchronization must therefore be performed first, as data synchronization may fail if the schemas are not identical.
Deploying the schema
To deploy the schema and save a basic report of the process, at the command prompt type:
sqlcompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/sync /v > "C:\SchemaDeploy.txt"
To create a more readable report of the schema differences and save a copy of the synchronization script used to deploy the changes type:
sqlcompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/Report:"C:\SchemaDiffReport.html"
/ReportType:Interactive
/ScriptFile:"C:\SchemaSyncScript.sql"
/sync
Where:
- /scr1:"C:\Scripts\WidgetScripts" specifies WidgetScripts as the source
- /db2:WidgetTest specifies WidgetTest as the target
- /o:Default specifies that the default SQL Compare options will be used for comparison and synchronization
- /sync synchronizes the data sources, making WidgetTest the same as WidgetScripts
- /v > "C:\SchemaDeploy.txt" directs detailed command line output to a file
- /Report generates a report of the schema differences and writes it to the specified file
- /ReportType specifies the format of the report
- /ScriptFile saves a copy of the SQL script used to migrate the changes
Deploying the data
To deploy the data and create a basic report, at the command prompt type:
/sqldatacompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/Exclude:table:WidgetPurchases
/sync /v > C:\DataDeploy.txt
To save a copy of the synchronization script used to deploy the changes type:
sqldatacompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/Exclude:table:WidgetPurchases
/ScriptFile:"C:\DataSyncScript.sql"
/sync /v > C:\DataDeploy.txt
Where:
- /scr1:"C:\Scripts\WidgetScripts" specifies WidgetScripts as the source
- /db2:WidgetTest specifies WidgetTest as the target
- /o:Default specifies that the default SQL Data Compare options will be used for comparison and synchronization
- /sync synchronizes the data sources, making WidgetTest the same as WidgetScripts
- /v > "C:\DataDeploy.txt" directs detailed command line output to a file
- /exclude:table:WidgetPurchases excludes WidgetPurchases. All other tables will be deployed.
- /ScriptFile saves a copy of the SQL script used to migrate the changes
Automating the process
To automate the deployment, save the command line as a .bat file:
cd "C:\Program Files\Red Gate\SQL Compare 8"
sqlcompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/Report:"C:\SchemaDiffReport.html"
/ReportType:Interactive
/ScriptFile:"C:\SchemaSyncScript.sql"
/sync
cd "C:\Program Files\Red Gate\SQL Data Compare 8"
sqldatacompare /scr1:"C:\Scripts\WidgetScripts" /db2:WidgetTest
/o:Default
/Exclude:table:WidgetPurchases
/ScriptFile:"C:\DataSyncScript.sql"
/sync /v > C:\DataDeploy.txt
You can then schedule deployment using the Microsoft® Windows® Scheduled Task wizard.
Additionally, you can automatically update the scripts in source control with the changes from the development database by using the development database as the source for the synchronization (/db1:WidgetDev) and a scripts folder as the target (/scr2:WidgetScripts).
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