How to Set Up Version Control for a SQL Server Database


How to Set Up Version Control for a SQL Server Database


Connect a SQL Server database to your source control system from within SQL Server Management Studio

Everyone knows that source code belongs in a version control system... but databases aren't typically stored in easily-versioned files.  A significant portion of code is left unsecured simply because committing it takes too much time, too much work.

This article will demonstrate how to solve this problem using VersionSQL, GitHub, and SQL Server Management Studio v18. The same steps apply to other source control repositories (authentication modes may vary) and SSMS versions. All software has been installed and the test system has network access to both the target SQL Server and GitHub.

Bridging the Gap

Open SQL Server Management Studio and connect to a SQL Server instance.  Right-click on your database in the Object Explorer pane and select "Connect to Version Control".  This will open the "Connect Database to Version Control" dialog.

VersionSQL Object Browser Context Menu

 

Copy the https repository path from GitHub and paste it into VersionSQL.

Copying the Repository Path from GitHub

VersionSQL Connect Database to Version Control Dialog


  After clicking OK you will be prompted to log in and grant VersionSQL access.

Authenticate to GitHub


That's it!  Your database is now connected to source control.  Continue on to check in your database scripts.

 

Saving Everything

A version control system connection does little good if nothing is ever checked in, so VersionSQL immediately prompts for a full commit after setup.

(Note: You can always initiate a full-database commit later by right-clicking on the database in the Object Explorer and selecting "Commit Entire Database")

VersionSQL Commit After Connect


Click Yes, optionally write a short log message in the window that appears, then click OK to begin sending data.

VersionSQL Commit Log Message


VersionSQL will script out all the objects in the database and send them to the version control system.

VersionSQL Commit Finished


The database objects are saved to plain-text .SQL files, just as if you had scripted and saved them all manually.

Committed SQL in GitHub

 

Congratulations!  You now have a version-controlled database.  A quick commit from time to time during development will produce an audit trail of revisions -- a historical record of database schema changes tracking who made each change and why.

Ready to save your SQL?

"We started a new IT project with multiple developers involved in it. We didn't want to lose track of database changes so decided to use a tool. VersionSQL suited our requirements. It is easy to use."


"Searching for a Git solution for my SQL Server development, I found VersionSQL to be the most adequate and easy to use compared to the alternatives. No hassle and no fuss, only does what needs to be done."

Contact

I love getting bug reports, reviews, and ideas!
Send me an email at [email protected] or using the form below.

Loading contact form...
Ask a question!