SQL Source Control - 3.1
Branching and merging - SQL Source Control
Many development projects involve creating branches, for a feature, a release, or some other development milestone. In some source control systems, branches are referred to as "forks". A branch is essentially a copy of the code base that shares its history. Branches diverge as required, and the process of reincorporating the changes from a branch is referred to as merging.
Development projects typically have a "trunk" which is the main code base, and branches which diverge from it.
For more information see:
For a general introduction to source control concepts, see:
- Version Control by Example by SourceGear founder Eric Sink.
SQL Source Control allows you to work with branches of a database, although it does not currently provide the means to create a branch or merge branches in SQL Server Management Studio.
To branch with SQL Source Control you must create the branch using your source control system, and then link to the appropriate branch.
For detailed information on branching, refer to the documentation for your source control system.
Working with branches
Once you have created a branch in source control, you are ready to work on it in SQL Server Management Studio with SQL Source Control.
There are two approaches to working with branches:
Un-link and re-link to the branch
Here, you continue working on the same database in SQL Server Management Studio, but link it to the branch in your source control system.
Once the branch is created, un-link it in SQL Source Control, then link the database to source control again. When you link, specify the location of the branch in source control.
Create a new database for the branch
Here, you create the branch in your source control system, and create a new database to link with it in SQL Server Management Studio.
Create a new empty database, and link it to source control in SQL Source Control. When you link, specify the location of the branch in source control, then on the Get Latest tab, update the database with the latest version from source control.
Merging
SQL Source Control does not provide automatic or line-by-line merging functionality. You can use SQL Source Control or SQL Compare to merge at an object level, but not to choose line-by-line changes.
When you merge with SQL Source Control or SQL Compare, you choose a version of each object to keep; for example you might keep the trunk version of a table, and the branch version of a view.
There are three approaches to merging:
Merging with your source control system
You can manually merge the branch changes back into the trunk using your source control system, as you would for application code.
This approach is recommended if the merge is complex, or if there are conflicts. For example if the same object has been modified in both the branch and the trunk.
When merging manually, you must ensure that referential integrity is maintained. Otherwise the database could be left in an invalid state.
Your source control system may include auto-merging functionality that simplifies manual line-by-line merges.
Merging with SQL Source Control
If you do not need to perform a line-by-line merge, you can merge with SQL Source Control.
To merge branch changes back into the trunk with SQL Source Control:
- Ensure that in SQL Source Control you have a database linked to the branch in your source control repository.
- Get the latest version and commit any outstanding changes.
- Unlink the database from the branch.
- Re-link the database to the trunk.
- Go to the Commit Changes tab.
The tab shows the changes to the branch as changes to commit.
If there are conflicts, choose Keep mine to override the trunk with the objects from the branch.
- Commit the changes.
The trunk is updated with the branch changes.
Merging with SQL Compare
If there are no conflicting changes between the branch and the trunk, you can merge automatically using SQL Compare.
To merge branch changes into the trunk with SQL Compare:
- In SQL Source Control, ensure you have a database linked to the trunk.
- Use your source control system to create a local copy of the latest branch version, for example by performing an SVN checkout.
- In SQL Compare, create a new project. Set the local copy of the branch as the source, and the trunk database as the target.
For more information, see: Setting data sources
- Compare the data sources.
SQL Compare shows the differences between the branch and the trunk.
- In the Results pane, select the objects from the branch that you want to merge into the trunk, and run the Synchronization Wizard, to synchronize the data sources
The trunk is updated with the changes from the branch.
- In SQL Source Control, on the Commit Changes tab, commit the trunk changes to source control.
See also |
Was this article helpful?
SQL Source Control
- Setting SQL Compare options within SQL Source Control
- "ICredentialsProvider is unset, therefore can't get" error occurring within SQL Source Control
- Linking fails due to SVN pre-commit hooks
- Logging changes to shared databases
- Object changed by Unknown
- Setting permissions for SQL Source Control
- Using SQL Source Control with Team Foundation Server 2012 or tfspreview.com
- Error: Failed to resolve no-ops after 5 tries
- Using SQL Compare or SQL Changeset scripts with SQL Source Control
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 Source Control
- Database development models
- Release notes - version 1.0
- Release notes - version 1.1
- Release notes - version 2.0
- Release notes - version 2.1
- Release notes - version 2.2
- Requirements & prerequisites
- Technical Overview
- Release notes - version 3.0
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

Step by step examples