SQL Compare - 9.0
Learning SQL Compare - 9.0
Worked example: Comparing and synchronizing two databases
This worked example demonstrates a basic comparison and synchronization of two SQL Server databases.
In the example, the Magic Widget Company has a SQL Server database running on a live web server. This database contains a number of tables, views, stored procedures, and other database objects. The Magic Widget Company's development team has been working on an upgrade to their website. As part of this upgrade, they have made a number of changes to the structure of the database. They have already transferred the changes from the development server to a staging server.
They now need to transfer the changes to the production server.
This example has four steps:
- Set up the databases
Create the example databases on your SQL Server.
- Set up the comparison
Specify the data sources you want to compare.
- Select objects to synchronize
Review the results and select the objects you want to synchronize.
- Synchronize the databases
Create and run a synchronization script.
1. Set up the databases
The worked example uses the following databases:
- WidgetStaging is the staging database
- WidgetProduction is the production database
To create these two databases on your SQL Server:
- If they already exist, delete the databases WidgetStaging and WidgetProduction.
- Click here to view the SQL creation script for the databases.
- Copy the script, paste it in your SQL editor application, and run it.
The databases and their schema are created.
2. Set up the comparison
- Start SQL Compare if it is not already running. The Project Configuration dialog box is displayed showing your most recent project:

You can edit the current project, or create a new project.
If you want to create a new project, click Cancel to close the dialog box, and on the toolbar click
(New Project) - In the shaded upper pane, ensure both Source and Target are set to Database.
In this example, we will compare databases. You can also compare backups, SQL Compare snapshots, and scripts folders.
- For each data source, in Server, type or select the name of the server on which you set up the databases.
- For the source, in Database, type or select WidgetStaging. Type or select WidgetProduction for the target.
If the databases are not displayed in the Database lists, right-click in each Database box and click Refresh, or scroll to the top of the list and click Refresh.
- Click Compare Now.
SQL Compare displays a message dialog box that shows the progress of the comparison.
When the comparison is complete, click OK to close the message box.
3. Select objects to synchronize
The results of the comparison are displayed in the upper (Results) pane:

The results are grouped by:
objects that exist in both databases but are different |
|
objects that exist in WidgetStaging but do not exist in WidgetProduction |
|
objects that exist in both databases and are identical |
To view the objects in a group, click
:

When you click an object, the lower (SQL Differences) pane shows a side-by-side, color-coded listing of the differences in the object creation scripts.
This example shows the WidgetReferences table:

For more information, see:
Use the check boxes in the middle of the upper (Results) pane to select objects for synchronization.
In this example, we will synchronize all objects that are different:
- On the Filter pane, ensure the default filter Nothing Excluded is selected.
The current filter defines which objects are displayed. When you use the filter to exclude an object, it is removed from the Results pane and cannot be selected for synchronization.
For more information, see Using filters
- In the central column of the Results pane, select the top level check box to include all objects in the synchronization:

All objects are selected, and the
Synchronization Wizard button becomes available. - Click
Synchronization Wizard
4. Synchronize the databases
On the first page of the Synchronization Wizard you can choose to create and save a synchronization script, or perform the synchronization using SQL Compare.
Choose synchronization method
In this example, we will synchronize using SQL Compare.

- Ensure that Synchronize using SQL Compare is selected.
- Clear the Back up target before synchronization check box if it is selected.
In this example, we will not back up before synchronization.
For more information, see Backing up before synchronization
- Ensure the Recompare after synchronization check box, and the Save a copy of the synchronization script check box are selected.
In this example, we will run the script from SQL Compare, and compare the databases afterwards to check the results. We will also save a copy of the synchronization script.
- Click Next
Review dependencies
SQL Compare checks for dependencies:

All the objects you selected for synchronization are listed. If the selected objects reference or are referenced by objects you did not select, and these dependencies affect the synchronization, the objects with dependencies are listed here.
For more information, see Using the synchronization wizard
In this example there are no dependencies. Click Next to review the synchronization script.
Review script
The final page of the wizard displays information about the synchronization:

There are three tabs on the Review page:
- Synchronization script shows the script to synchronize the data sources.
You can search the script, save it, or copy it to the clipboard.
- Summary shows a synopsis of the actions in the synchronization script.
You can view the summary grouped by the objects affected, by the type of modification, or by the order in which the script modifies the target.
- Warnings shows a list of any warnings about unexpected behavior that may occur when you synchronize the databases.
For more information, see Warnings
In this example, SQL Compare displays a warning to inform you that it cannot use the ALTER TABLE command to change the IDENTITY column, so the synchronization script will rebuild the WidgetReferences table.
Warnings are displayed whenever tables require rebuilding as these may be slow operations. Data in tables is preserved when tables are rebuilt.
Performing the synchronization
When you have reviewed the script, synchronize the databases:
- Click Synchronize Now to perform the synchronization.
- A confirmation dialog box is displayed. Click Synchronize Now to continue.
- SQL Compare displays a message dialog box that shows the progress of the synchronization.
When the synchronization is complete, click OK to close the message box.
SQL Compare then re-compares the databases. The results are shown in the main window. In this example, all objects are shown to be identical, confirming that the synchronization has been a success:

See also |
Was this article helpful?
SQL Compare
- Logging and log files
- Stored Procedures and Functions created with wrong name
- Synchronization scripts may be in incorrect version of SQL syntax
- Extended properties not permitted error (version 5.2)
- CLR Procedures' permissions are not recreated (version 5)
- Support for 'returns NULL on NULL Input' in CLR functions (version 5)
- Project files (scp files) suddenly appear on desktop (version 5)
- Stored procedures using full-text queries fail to synchronize
- When does the synchronization process rebuild tables?
- Unable to begin a distributed transaction error synchronizing databases
- User or role already exists in the current database error
- Clarification on the "Ignore Triggers" option in the SQL Compare command-line version
- Common table expressions returned by User Defined Functions may fail
- Can't compare encrypted text in SQL Server 2005, 2008
- Exception when connecting to SQL Server (Version 6)
- SQL comparison and synchronization automation capabilities
- Error logging in SQL Compare 6.2
- Using Team Foundation Server source control system
- Creating a SQL 2000 compatible database from a SQL 2005 database using SQL Compare
- Support for numbered stored procedures
- SQL Compare 7 Object-level restore
- Index was outside the bounds of the array error when registering databases X64
- HTML reports are generated for identical comparisons
- Comparison may seem slower than necessary
- DEFAULT_SCHEMA clause cannot be used with a Windows group
- SQL Compare may drop and create CLR assemblies
- SDK activation prompt may appear when starting a new SQL Compare project
- Column does not allow nulls. INSERT fails
- This SQL Server has been optimized for x concurrent queries.
- SQL Compare comparison differences
- Using SQL Server Management Studio Express as a query editor
- How to force SQL Compare and SQL Data Compare to use an Encrypted Connection
- Invalid SQL when synchronizing an index to a scripts folder when data compression is specified
- Tips
- Changes to distribution of command line
- Common error messages
- Copying the structure of a database
- Permissions required to use SQL Compare
- Rollback on script failure or cancellation
- Errors in scripts folders
- Logging and log files
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 Compare
- Activating your products
- Activating your products
- Getting help offline
- Release notes - version 9.5 EAP
- Introducing SQL Compare 8: FAQs for SQL Compare 7 users
- Release notes - version 10.xx
- SQL 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 Compare
Setting up the comparison