Lesson 2 of 4 Source Control and Deployment Pipelines

Branching, Pull Requests and Merge Conflicts

This lesson explains branching models for SQL projects, what reviewers check and how to resolve merge conflicts.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why short-lived branches suit database changes.
  • Identify what to review in a database pull request.
  • Describe how to resolve textual and semantic conflicts.

Branching models

Most teams use trunk-based development with short-lived feature branches: each change is made on a branch, kept small and merged into main within days through a pull request. Long-lived branches drift from main and produce larger conflicts, especially in shared tables. Release branches are created when a version must be patched while main moves on, and fixes are merged back to main so they are not lost.

True or false

Branching

Exam skills 2.3.5

Decide whether each statement about branching is true.

Log in to try this activity Interactive activities are free with an account.

What reviewers check

A database pull request is reviewed with more than the diff of .sql files. The pipeline attaches the build result, code analysis warnings, test results and, ideally, a deploy report or script against a staging database. Reviewers look for possible data loss (dropped or narrowed columns), blocking operations on large tables such as adding indexes or columns that rebuild the table, missing indexes on new foreign keys, security changes such as new GRANT statements, and changes to reference data.

Select all that apply

Reviewing a database pull request

Exam skills 2.3.5

Identify what reviewers should look for in a database pull request.

Log in to try this activity Interactive activities are free with an account.

Merge conflicts

Because each object has its own file, developers changing different objects merge without conflicts. A conflict occurs when two branches change the same lines of the same object, for example both adding a column at the end of the same table. Git marks the conflicting section, and the developer edits the file to the intended final definition containing both columns, removes the markers, rebuilds the project to validate references and reruns tests. Updating the branch from main (merge or rebase) before completing the pull request surfaces conflicts early. Conflicts can also be semantic without a textual conflict, such as one branch dropping a column that another branch's new view uses, which the build after merging catches.

Renaming objects needs care: a rename in the project should be recorded in the refactor log (or handled with a pre-deployment sp_rename script), because otherwise the deployment drops the old object and creates a new empty one.

Scenario questions

Resolving conflicts

Exam skills 2.3.5

Choose how to handle each merge situation.

Log in to try this activity Interactive activities are free with an account.
Worked example

Two developers, one table

Developer A adds a Discount column to Sales.Orders on one branch, and developer B adds a Channel column to the same table on another. B's pull request merges first, and A's now shows a conflict in Orders.sql. How should A resolve it?

Merge main into the branch (or rebase), edit Orders.sql so the CREATE TABLE statement includes both Channel and Discount, remove the conflict markers, rebuild the project and rerun the tests before completing the pull request. Accepting only A's version would remove B's column from the model, so the next deployment would try to drop it, which BlockOnPossibleDataLoss would block if it has data.

Check yourself

Why should a column rename be recorded in the refactor log?

Show answer

Without it, SqlPackage sees a dropped column and a new one, and would drop the data instead of renaming.

Exam Tips

Remember for the exam

  • Short-lived branches merged through pull requests reduce conflicts.
  • Resolve conflicts to the intended final definition, then rebuild and test.
  • Review deploy reports for data loss and blocking operations, not just the diff.
  • Record renames in the refactor log so deployment renames instead of dropping.