Resolve conflicts

dbForge Source Control helps to resolve conflicts as a result of discrepancies between the latest version of an object/data in version control and in your local database.

The most common reason for conflicts is when several people simultaneously make different changes on the same objects/data.

The guide provides the following instructions:

Before you can use the Source Control Manager, you must first link a database to the version control repository by following the steps outlined in the relevant how-to topic:

The linked database gets the following icon in Object Explorer:

Source Control label

dbForge Source Control checks whether any changes were made to the database locally or remotely and whether these changes were committed to the repository. In the same way, dbForge Source Control checks whether any changes were committed to the version control and whether these changes were deployed to the linked database.

In addition, the tool checks for conflicts that can occur when multiple developers are making changes to the same file both in the repository and in the local database.

The Refresh progress window opens automatically, showing the stages of the refresh operation.

Refresh

After the refresh operation is complete, the Source Control Manager opens displaying all the changes in the following sections:

It should be noted that Source Control Manager can display either all three sections, or two of them, or just one section.

The tool distributes the changes in the following sections

Note

Local changes section

  • The Add change type indicates that the object was created locally in the database that is being version-controlled using Source Control, and has not been committed to the remote repository yet. Selecting the object and clicking Undo will remove iit from the local database.
  • The Remove change type means that the object was deleted from the local database that is being version-controlled using Source Control, but is still present in the remote repository. Selecting the object and clicking Undo will restore it in the local database.
  • The Modify change type signifies that changes were made to the object in the local database that is being version-controlled using Source Control. As a result, the object’s DDL in the local database differs from the version stored in the remote repository. Selecting the object and clicking Undo will discard the changes made to the object in the local database, reverting it to the version from the repository.

Remote changes section

  • The Add change type indicates that the object has been added to the remote repository since the last synchronization, and is not present in the local database that is linked to this repository via Source Control. Clicking Get Latest will add the object to the local database.
  • The Remove change type means that the object has been removed from the remote repository since the last synchronization but is present in the local database that is linked to this repository via Source Control. Clicking Get Latest will remove the object from the local database.
  • The Modify change type indicates that the object has been modified in the remote repository since the last synchronization. As a result, the object’s DDL in the repository differs from the version stored in the local database that is linked to this repository via Source Control. Clicking Get Latest will update the object in the local database to match the version from the repository.

If the database and version control repository are identical and no changes are found, the following window is displayed:

The database and version control repository are identical

To resolve a conflict:

In the Conflicts section, select the checkboxes next to the conflicts that you want to resolve.

Note

If you select the checkbox next to Conflicts, all conflicts will be selected.

The Conflict window

As you can see in the screenshot above, the Source Control grid contains the following columns:

Column Description
Change Type Actions to be applied to the object or static data; in this case, the single available change type is Conflict
Type The type of the object
Name The name of the object that will undergo changes; a <name> (Data) construction refers to static data
Owner The schema or database in which the object was created

Select the required way to resolve your conflict:

  • Get Local: Your version of the object/data will be committed to source control.
  • Get Remote: Your changes will be discarded. The local database will be updated with the latest version of the object/data from source control.

When you click Get Local, the changes are then displayed in the Local changes section of the Source Control Manager.

When you click Get Remote, the changes are then displayed in the Remote changes section of the Source Control Manager.

After that, you can work with the changes from the Local changes section, as described in Commit changes, and with the changes from the Remote changes section, as described in Get the latest version.

Conflicts with static data

A conflict arises when multiple developers work on the same static data, such as reference or contact information. This happens when one developer makes changes locally, while another modifies data in the remote repository simultaneously. Therefore, a source control system cannot identify whose changes to apply and marks them as conflicts. As a result, these conflicts must be resolved before committing them to the repository or fetching the latest changes from the remote repository.

The Conflict window for static data

The bottom grid of the Source Control Manager for the Conflict section is divided into the following groups:

Group Description
All All records of the table
Only in Database Records that exist only in a database but are not stored or managed within the source control system
Different Data that has differences, and where the conflict arises
Only in Version Control Data that is present only in a version control system but does not exist in the local working directory
Identical Data that has the same content or version both locally and remotely

Note

Keep in mind that data changes may not apply without the related schema changes. If you have applied both schema and data changes to a database object, you need to commit them simultaneously. Similarly, if you are pulling someone else’s schema and data changes, pull them simultaneously.

Therefore, if you have a schema conflict and a data change on an object, the change cannot be committed or retrieved without resolving the schema conflict beforehand.

Let us demonstrate the conflicts and their resolution on an example.

Example

This example demonstrates how to resolve conflicts between developers using the Source Control tool in dbForge Studio for SQL Server. Suppose two sample databases, BikeStoresDev1 and BikeStoresDev2, contain the same tables.

The workflow is as follows:

Step 1: Linking databases to the repository

1. Link both databases to the same version control repository, for example, development.

2. After that, the Source Control Manager opens for each database, displaying local changes or indicating that the databases are identical.

Step 2: Modifying database objects by developers

1. The first developer (Dev1) modifies the production.brands table:

USE BikeStoresDev1
GO

IF DB_NAME() <> N'BikeStoresDev1' SET NOEXEC ON
GO
ALTER TABLE production.brands
ADD brand_description varchar(500);
GO
SET NOEXEC OFF
GO

2. The second developer (Dev2) also makes the changes to the production.brands table and commits them to the repository:

USE BikeStoresDev2
GO

IF DB_NAME() <> N'BikeStoresDev2' SET NOEXEC ON
GO
ALTER TABLE production.brands
ADD brand_description varchar(50);
GO
SET NOEXEC OFF
GO

3. Dev1 modifies the production.categories table:

USE BikeStoresDev1
GO

IF DB_NAME() <> N'BikeStoresDev1' SET NOEXEC ON
GO

ALTER TABLE production.categories
ALTER COLUMN category_name varchar(255) NULL;
GO

SET NOEXEC OFF
GO

4. Dev2 modifies the same table - production.categories - and commits these changes to the repository:

USE BikeStoresDev2
GO

IF DB_NAME() <> N'BikeStoresDev2' SET NOEXEC ON
GO

ALTER TABLE production.categories
ALTER COLUMN category_name nvarchar(255) NOT NULL;
GO

SET NOEXEC OFF
GO

5. Dev1 modifies the sales.customers table:

USE BikeStoresDev1
GO

IF DB_NAME() <> N'BikeStoresDev1' SET NOEXEC ON
GO
ALTER TABLE sales.customers
  ADD skype varchar(50) NULL;
GO

6. Dev2 modifies the sales.orders and sales.customers tables and commits these changes to the repository:

USE BikeStoresDev2
GO

IF DB_NAME() <> N'BikeStoresDev2' SET NOEXEC ON
GO
ALTER TABLE sales.orders
  DROP CONSTRAINT FK_orders_customers;
GO
ALTER TABLE sales.customers
  ADD skype varchar(60) NULL;
GO

Step 3: Detecting conflicts

Dev1 refreshes the Source Control Manager of the BikeStoresDev1 database. Source Control detects the changes and displays them in the following sections:

  • Conflicts: Displays the sales.brands, sales.categories, and sales.customers tables with the Conflict change type.
  • Remote changes: Shows the sales.orders table with the Modify change type.

Note

The sales.orders table appears in the Remote changes section because its modification is directly related to the deletion of the relationship between the sales.orders and sales.customers tables.

Dev1 - Conflicts

Step 4: Resolving conflicts

Dev1 decides to resolve the conflicts as follows:

  • Commit their local changes to the sales.customers table, overriding the changes made by Dev2.
  • Get remote changes for the production.categories and production.brands tables.

Committing local changes

1. In the Conflicts section, select the checkbox next to the sales.customers table and then select Get Local.

Dev1 - Conflicts: Get Local

The sales.customers table moves to the Local changes section with the Modify change type.

2. In the Local changes section, select the checkbox next to the table, write a comment, and then select Commit.

The Commit progress window opens, followed by the Refresh progress window, which updates the Source Control Manager of the BikeStoresDev1 database.

Dev1 - Conflicts: Local Changes

Getting remote changes

1. In the Conflicts section, select the checkboxes next to the production.categories and production.brands tables and select Get Remote.

Dev1 - Conflicts: Get Remote

2. The tables appear in the Remote changes section. Dev1 can now update the BikeStoresDev1 database with the changes made by Dev2 by following the steps in the Get the latest version topic.

Dev1 - Remote changes

Note

If necessary, conflicts can be restored to their previous state. To do this, select Refresh.

For more information about how to commit the changes to the repository, see Commit changes.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Source Control for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Source Control in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Source Control for your business, request a demo to see it in action.
Ready to start using dbForge Source Control for SQL Server?