Version-controlling
SQL Server Databases
in GitHub

This article is dedicated to the aspects of version-controlling SQL Server databases in GitHub with dbForge Source Control.

The described workflow of source-controlling databases applies to all version control systems supported by dbForge Source Control. The choice of GitHub for this article is motivated by the ever-growing popularity of cloud-based version control systems. With Source Control, you can easily:

  • commit and revert changes
  • view and resolve conflicts
  • track changes
  • link static data.

Link a database to Source Control

The first step you should take after downloading and installing dbForge Source Control is to link a database to a remote GitHub repository. For this, right-click a database in Object Explorer, click Source Control, and then select Link Database to Source Control.

dbForge Source Control supports Git for Windows client so that you can work with all possible connection and authentication types, as this task is delegated to the Git client.

To link your database to a Git repository, you need to only specify a folder or a sub-folder in a local Git repository where dbForge Source Control for SQL Server will store SQL scripts.
dbForge Source Control - Link a database to Source Control

Select Git source control repository

In the Link Database to Source Control wizard that opens, specify a connection and a database you want to connect to the source control system. In the Source Control repository field, click Manage to open Source Control Repository Properties window.

Next, select Git as a Source Control system and provide a path to the repository folder on your computer, which is a clone of your remote GitHub repository. Finally, select a database development mode and click the Link button. We select the Dedicated model, where each developer works with his own copy of the database.

dbForge Source Control - Select Git source control repository

Initial commit

You'll see the following Source Control Document window after successful database linking. Since currently our remote repository is empty, we need to commit our database files to it. To do this, we just need to select all files in the Local Changes section of the document, write a comment, and click the Commit button.

When the commit is over, the document will show that there are no changes in database objects, which means that our local database files and the ones at GitHub are absolutely identical.

Basically, all changes you make in your local database will be represented on the Local Changes tab. If you do not want to commit certain changes, click the Undo button, and all your local changes will be reverted.

dbForge Source Control - Initial Commit

Associating Commits with GitHub Issues

With dbForge Source Control, you can easily associate your commits of local changes with GitHub Issues as well as close GitHub Issues right from dbForge Source Control.

To associate a commit with an issue, you need to specify the issue number with the '#' symbol in the Comment text box before committing local changes.

To close an issue, you need to add a keyword before the issue number in the Comment text box before committing local changes. You can use any of the following keywords: Close, Closes, Closed, Fix, Fixes, Fixed, Resolve, Resolves, Resolved.

dbForge Source Control - Associating Commits with GitHub Issues

Remote changes

When other developers modify database files and commit their changes to the repository, these changes are represented in the Remote Changes section of the Source Control Document. All you need to do for updating your local database is to select changes and click the Get Latest button.

In the lower part of the Source Control Document window, you can see SQL scripts for database objects.

dbForge Source Control - Remote changes

Conflicts

Conflicts happen when you and other developers modify the same database object or its property. In dbForge Source Control, conflicts are displayed in the Conflicts section of the Source Control Document. To resolve a conflict, select it in the Conflicts list and click Get Local to override remote changes with your local ones, or Get Remote if you want to override your local changes with the remote ones.

The Source Control Document also shows DDL diffs for the conflicts, so you will instantly know the reason for the conflict.

Execute procedure in MySQL - Breakpoints

Conclusion

With dbForge Source Control, managing database changes in source control systems is quite simple and straightforward. It will take you just a couple of minutes to link your database to your favorite source control repository, get the latest changes from the repository, or to update it with your local changes. Download and try dbForge Source Control on your own.

Source Control is a part of SQL Tools

SQL Tools includes a pack of essential SSMS add-ins and tools