📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What do Boyce-Codd normal form, fourth normal form and fifth normal form fix that third normal form does not? Give an example of each, and tell me how much they matter in a real SQL Server schema.

Covers BCNF (determinants that are not candidate keys), 4NF (independent multi-valued facts) and 5NF (join dependencies), with examples and their practical relevance for SQL Server OLTP design.

Intermediate Theory Intermediate bcnf data-modelling database-design normal-forms normalisation sql-server

🎯 Key points

  • BCNF: every determinant must be a candidate key
  • A 3NF table can only violate BCNF if it has overlapping composite candidate keys
  • 4NF: no independent multi-valued facts in one table
  • Skills and languages per employee in one table cause a cross product
  • 5NF: no join dependency that is not implied by candidate keys
  • 5NF example: supplier-part-project with a cyclic business rule
  • BCNF can lose a dependency, needing an indexed view or trigger
  • More decomposition means more joins: weigh read cost against anomaly risk

⏱ 30-second answer

BCNF tightens 3NF: every determinant must be a candidate key. It only bites when a table has overlapping composite candidate keys, e.g. a tutoring table where each tutor teaches one subject. 4NF removes independent multi-valued facts stored together: an employee's skills and languages in one table force a cross product of rows. 5NF removes join dependencies: a table that can be split into three and rejoined without loss, because of a cyclic rule like "if a supplier supplies a part, and a project uses that part, and the supplier works with the project, then the supplier supplies that part to that project".

In practice, a sensible 3NF design with one table per independent relationship is almost always already in BCNF and 4NF; 5NF cases are rare. The value is spotting the smell, not chasing the label.

🗣 Full answer (senior)

How I would answer this in an interview

"Third normal form says non-key columns depend on the key and nothing else. Boyce-Codd normal form goes one step further: every determinant, meaning anything that functionally determines another column, has to be a candidate key. The difference only shows up when a table has overlapping composite candidate keys. The textbook case is a Tutoring table of Student, Subject and Tutor, where each tutor teaches only one subject. Tutor determines Subject, but Tutor isn't a key, so you can record the same tutor against two subjects by mistake. Splitting it into TutorSubject and StudentTutor fixes it.

Fourth normal form is about multi-valued dependencies. If an employee has several skills and, independently, several languages, and you store both in one EmployeeSkillLanguage table, you have to store every combination. Add one language and you add a row per skill. The fix is two tables, EmployeeSkills and EmployeeLanguages. Fifth normal form deals with join dependencies: a three-way table that can be losslessly rebuilt by joining three two-way tables, because a business rule makes the three-way fact derivable. If the rule really holds, storing the three-way table invites inconsistency.

The mistake I see is people either dismissing these as academic or contorting a schema to chase them. In a real SQL Server OLTP design, if you model each independent relationship as its own table, you get BCNF and 4NF almost for free, and genuine 5NF problems are rare. What I actually use them for is code review: when I see a three-column junction table I ask whether the three facts are really one fact. If the answer is no, it's a 4NF problem waiting to produce duplicate rows."


What each form adds

Form Rule Typical smell Fix
3NF No transitive dependency on the key Orders.CustomerEmail Move to Customers
BCNF Every determinant is a candidate key A non-key column determines part of a composite key Split on the determinant
4NF No independent multi-valued facts together Three-column junction table of two unrelated lists One table per list
5NF No join dependency not implied by keys Three-way table derivable from three pairs Three pair tables (only if the rule truly holds)

BCNF example

Tutoring(StudentId, Subject, TutorId), rule: a student has one tutor per subject, and each tutor teaches one subject.

  • Candidate keys: (StudentId, Subject) and (StudentId, TutorId).
  • TutorId → Subject, but TutorId alone is not a key: 3NF holds (Subject is part of a key), BCNF fails.
  • Fix: TutorSubjects(TutorId PK, Subject) and StudentTutors(StudentId, TutorId).
  • Trade-off: "one tutor per subject per student" can no longer be a simple unique constraint; you enforce it with a trigger, an indexed view or application logic. BCNF decompositions sometimes lose a dependency, which is why 3NF is the usual target.

4NF example

EmployeeId Skill Language
7 C# English
7 C# Nepali
7 SQL English
7 SQL Nepali

Adding "Azure" needs two rows; forgetting one implies "Azure but only in English", a fact nobody stated.

Practical weight

Situation Does it matter?
Typical line-of-business OLTP 3NF with one table per relationship; BCNF and 4NF follow
Junction tables with 3+ foreign keys Check for 4NF and 5NF
Reporting schemas Deliberately denormalised; not relevant

Production example

A rostering system [you can describe] stored StaffQualificationSite(StaffId, QualificationId, SiteId) when qualifications and permitted sites were independent. A new site meant inserting one row per qualification, and the roster screen showed staff as unqualified at [N] sites because rows were missed. Splitting it into two tables removed about [60]% of the rows and the inconsistency.

🔍 What the interviewer is checking

Checks depth beyond the usual 3NF answer and, more importantly, practical judgement about whether it matters.

Green flags

  • Defines BCNF in terms of determinants and candidate keys
  • Gives a 4NF example with independent multi-valued facts
  • Knows BCNF can lose a dependency
  • Says most good 3NF schemas are already BCNF and 4NF

Red flags

  • Cannot give any example beyond 3NF
  • Insists every schema must reach 5NF
  • Confuses 4NF with denormalisation

📚 Learn in depth

1. Determinants and candidate keys

A determinant is any set of columns X with X → Y. A candidate key is a minimal set of columns that determines every column. 3NF allows a non-key determinant if the dependent column is part of some candidate key; BCNF does not. That loophole is the whole gap between them.

Tutoring(StudentId, Subject, TutorId)
  (StudentId, Subject) ──► TutorId        key dependency: fine
  TutorId ──────────────► Subject         determinant is not a key: breaks BCNF

2. Why BCNF can lose dependencies

Decomposing into TutorSubjects(TutorId, Subject) and StudentTutors(StudentId, TutorId) is lossless (joining gives back the original rows), but the rule (StudentId, Subject) → TutorId now spans two tables. SQL Server cannot express a unique constraint across a join directly; options are an indexed view with a unique clustered index on (StudentId, Subject), a trigger, or validation in the write path. This is the classic reason textbooks say "3NF is always achievable while preserving dependencies; BCNF is not".

3. Multi-valued dependencies (4NF)

A multi-valued dependency EmployeeId →→ Skill means the set of skills depends on the employee, independently of other columns. When two independent MVDs share a table, the table must hold their Cartesian product to stay consistent.

Employee 7: Skills {C#, SQL} × Languages {English, Nepali} = 4 rows
Add Azure:  {C#, SQL, Azure} × {English, Nepali}           = 6 rows (2 inserts)

In EF Core this usually appears when someone maps a single many-to-many join entity with three foreign keys because "they all relate to the employee".

4. Join dependencies (5NF)

A join dependency says a table equals the join of some of its projections. With the rule "if supplier S supplies part P, project J uses part P, and S supplies project J, then S supplies P to J", the table SupplierPartProject equals SupplierPart ⋈ PartProject ⋈ SupplierProject. Storing the three-way table means it can contradict the three pairs. Without that rule (the common case), the three-way table is a genuine fact and is already in 5NF.

5. Where the forms show up in .NET work

  • Junction tables in EF Core skip navigations: check every extra key column.
  • Permission models: UserRoleTenant vs UserRoles plus RoleTenants.
  • Product catalogues: ProductColourSize is fine if each combination is a SKU, a 4NF problem if colours and sizes are independent.

6. Higher forms beyond 5NF

Domain-key normal form and 6NF exist. 6NF (one non-key column per table) is used in temporal and anchor modelling; SQL Server temporal tables solve most of the same need without it.

Try it yourself

  1. Build Tutoring, insert a tutor against two subjects, and see that no constraint stops it.
  2. Decompose to BCNF and enforce (StudentId, Subject) uniqueness with an indexed view.
  3. Create the 4NF EmployeeSkillLanguage table, add a skill, and count the rows you need.
  4. Review a junction table in a project you know and write down whether its columns form one fact or two.

💻 Code

BCNF decomposition of the tutoring table, with the lost dependency enforced by an indexed view.

CREATE TABLE dbo.TutorSubjects
(
    TutorId int          NOT NULL PRIMARY KEY,  -- TutorId -> Subject is now a key dependency
    Subject nvarchar(50) NOT NULL
);

CREATE TABLE dbo.StudentTutors
(
    StudentId int NOT NULL,
    TutorId   int NOT NULL REFERENCES dbo.TutorSubjects (TutorId),
    CONSTRAINT PK_StudentTutors PRIMARY KEY (StudentId, TutorId)
);
GO

-- Re-enforce "one tutor per subject per student" across the two tables.
CREATE VIEW dbo.vStudentSubject
WITH SCHEMABINDING
AS
SELECT st.StudentId, ts.Subject
FROM dbo.StudentTutors AS st
JOIN dbo.TutorSubjects AS ts ON ts.TutorId = st.TutorId;
GO

CREATE UNIQUE CLUSTERED INDEX UX_vStudentSubject
    ON dbo.vStudentSubject (StudentId, Subject);

4NF: two independent lists become two tables.

-- Before: every skill x every language
-- CREATE TABLE dbo.EmployeeSkillLanguage (EmployeeId int, Skill nvarchar(50), Language nvarchar(50), ...)

CREATE TABLE dbo.EmployeeSkills
(
    EmployeeId int          NOT NULL,
    Skill      nvarchar(50) NOT NULL,
    CONSTRAINT PK_EmployeeSkills PRIMARY KEY (EmployeeId, Skill)
);

CREATE TABLE dbo.EmployeeLanguages
(
    EmployeeId int          NOT NULL,
    Language   nvarchar(50) NOT NULL,
    CONSTRAINT PK_EmployeeLanguages PRIMARY KEY (EmployeeId, Language)
);

⚠ Common mistakes

  • Mistake: Saying BCNF and 3NF are the same thing. Why it is wrong: BCNF requires every determinant to be a candidate key; 3NF allows a non-key determinant when the dependent column is part of a candidate key. In practice a 3NF table only breaks BCNF when it has overlapping composite candidate keys. Instead: explain the tutoring-style example.
  • Mistake: Storing two independent lists in one three-column junction table. Why it is wrong: forces a Cartesian product and implies facts nobody stated. Instead: one table per independent multi-valued fact.
  • Mistake: Splitting every three-way table "for 5NF". Why it is wrong: most three-way facts are genuine and cannot be rebuilt from pairs. Instead: only decompose when a business rule makes the three-way fact derivable.
  • Mistake: Decomposing to BCNF and forgetting the dependency that now spans tables. Why it is wrong: the original rule is no longer enforced. Instead: enforce it with an indexed view, trigger or validated write path, or stay at 3NF.
  • Mistake: Arguing about normal-form labels in a design review. Why it is wrong: the goal is removing anomalies, not passing a quiz. Instead: name the redundant fact and the bug it will cause.

🏛 Senior insight: trade-offs

Higher normal forms are a lens for spotting redundancy in junction tables, not a target to chase. The senior judgement is knowing that BCNF can cost you a constraint, that 4NF problems are common in permission and catalogue models, and that 5NF only applies when a real business rule makes a fact derivable.

Performance rarely decides it for OLTP: a 4NF split usually makes tables smaller (no Cartesian product), so writes and scans get cheaper, and the extra join is an index seek. Decomposition hurts in read-heavy reporting over millions of rows, which is why analytical models (star schemas, columnstore reporting tables) deliberately go the other way. Measure the actual query before using performance as the reason to keep a 4NF violation.

Option When it fits Cost When not to
Stop at 3NF Decomposing further would lose an enforceable rule Small residual redundancy When the redundancy already causes bugs
BCNF Non-key determinants cause inconsistent rows Cross-table rule needs an indexed view or trigger Rule is easier to keep as a unique constraint in 3NF
4NF split Two independent lists per entity One more table and join The combination itself is a real entity (a SKU)

🔗 Follow-ups the interviewer may ask

  1. When: Candidate struggles to define functional dependencies. Why: Checks the foundation the higher forms build on.
    How to answer

    Normalisation is organising tables so that each fact is stored once, in the table whose key it depends on, so the data cannot contradict itself. Redundant copies cause anomalies: an update anomaly (change a customer's email in one row but not the other 40), an insert anomaly (cannot record a product until someone orders it) and a delete anomaly (deleting the last order loses the customer).

    • 1NF: atomic values, no repeating groups, every row identified by a key.
    • 2NF: every non-key column depends on the whole key, not part of a composite key.
    • 3NF: no transitive dependencies: non-key columns depend on the key, not on other non-key columns.

    A price on an order line is not a copy: it is the price charged on that day, a different fact from today's list price. For OLTP I design to 3NF and only denormalise where a measured read cost justifies the extra write and consistency cost.

  2. When: Candidate mentions BCNF losing a dependency. Why: Checks knowledge of indexed views, triggers and their trade-offs.
    How to answer

    Options, in order of preference:

    • Indexed view with SCHEMABINDING and a unique clustered index over an inner join of the two tables. SQL Server enforces it on every write in the same transaction. Limits: inner joins only, deterministic expressions, required SET options, and extra write cost and lock contention on hot keys.
    • Set-based AFTER trigger that checks inserted against the other table and rolls back. Flexible, but hidden logic, extra latency on every statement, and it must use locking hints (UPDLOCK, HOLDLOCK) to be race-safe.
    • Validation in the write path inside a transaction with UPDLOCK, HOLDLOCK (or serializable). Works only if every writer goes through it and reduces concurrency on the checked range.

    Prefer the indexed view for pure uniqueness; measure insert latency before and after.

↩ Usually asked after

More in Database Design

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me