SQL Source Control - 3.1

SQL Source Control

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:

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:

  1. Ensure that in SQL Source Control you have a database linked to the branch in your source control repository.
  2. Get the latest version and commit any outstanding changes.
  3. Unlink the database from the branch.
  4. Re-link the database to the trunk.
  5. 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.

  6. 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:

  1. In SQL Source Control, ensure you have a database linked to the trunk.
  2. Use your source control system to create a local copy of the latest branch version, for example by performing an SVN checkout.
  3. 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

  4. Compare the data sources.

    SQL Compare shows the differences between the branch and the trunk.

  5. 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.

  6. In SQL Source Control, on the Commit Changes tab, commit the trunk changes to source control.

See also

Conflicts

Linking a database to source control

Getting a specific version

Deploying a database from source control

Was this article helpful?

Search support
Forums

SQL Source Control

all SQL products

all products