As I write more code, especially database code, and I collaborate with others (or myself), I find that I have the need to merge code more and more. It’s inevitable, and since I work across a couple machines, I even find that I need to merge my own code at times.
One way to do this well is use a merge tool of some sort. KDiff3 is a popular one, that’s free, and it’s one that integrates nicely with SQL Source Control, which I also use for various tasks.
If you install KDiff3 (use “choco instal kdiff3”) then you get a basic tool that allows you to compare files. If you start it, you’ll get a simple interface that lets you select multiple files and view them together in one interface. If you don’t use version control, apart from making a mistake, you also probably manage code like this.
Or you might have this:
Either way creates problems. If you have multiple people doing this, then you have other issues.
KDiff gives you a nice interface to see the differences between files. As you can see below, I have the changes marked in each file.
I can edit the files directly, or choose to merge them together. If I do the merge, I’ll get a third window that has the merged code.
As you can see, if I click the merge area, I can choose the code from either of the original files.
On the right is a scroll bar that lets me know where in the file the differences are.
Software developers think nothing of these types of tools, but DBAs aren’t as easily used to using tools like this. I’d suggest that you download kdiff3 and give it a chance in trying to reconcile any code between team members or servers.
And start using Version Control. It’s easy and incredibly useful.