One of the hassles of working in a development team is that you will have conflicts between your code and another developer’s. That’s fine, and it’s a natural effect of allowing each person to work on parts of a database independently.
However resolving conflicts can be a pain. Fortunately there are some nice utilities that can help make the process easier.
Here’s a quick example. I was simulating two developers, each with their own database, but linked to a common Git VCS repository. I went to commit a change and got this:
SQL Source Control detects a conflict before committing the stored procedure on the left. As you can see, it has more fields in it, while the version in my VCS has a TOP clause. I can keep my version or update mine with what’s in VCS.
Or, if you look to the right, you can see I have the option to “Merge” code. If I click Merge, then I’ll open KDiff3, which is installed on my system. SQL Source Control has detected this and given me the chance to resolve the issue.
I get a message that there are 3 conflicts, and none of them could be resolved. If there are places where the code can be merged automatically, KDiff3 will do that.
Once I acknowledge this, I see my code. This looks like what I saw in SQL Source Control. My code is on the left, and the version from VCS is on the right. Below is the merged code, which has some placeholders where the code conflicts.
If I right click the first conflict, I get some choices. In this case, I’ll take the line from the left, which has no TOP clause.
This gets inserted into my code and I can move on to the second conflict. In this case, I’ll take the version on the right, which has nothing.
For the last conflict, I’ll also take the missing fields from the right.
If I now save and close KDiff3, I’ll get the merged code in SSMS and SQL Source Control.
Not the “Keep mine” is selected. I’ll commit this, which will be the most up to date version in our VCS. Other developers can update their code with this version, and if they have conflicts, SQL Source Control and KDiff3 make them easy (ier) to resolve.
I’ll be showing you some basics of using a VCS with your database at SQL in the City 2015 this October. You can see this and more in London on October 16 or Seattle on October 26. If you can come to either event, register today and come pick up a few tips and tricks.