Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 106/ 160
06. Database Design, Normalization & Semi-Structured SQL

Boyce-Codd Normal Form (BCNF) & Higher Normal Forms

Push beyond 3NF into BCNF and understand when 4NF/5NF matter.

AdvancedBCNF · Higher NFs3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Every fact in a table should be decided by something that identifies a whole row. If something smaller decides a fact, split that fact into its own table.

Think of it like…

Club rules: "every rule must be decided by the membership card number" (BCNF). A rule like "each coach teaches only one sport", decided by the coach rather than by the membership, breaks it, even if it sounds harmless.

Where you’ve seen it

class_bookings(student, subject, teacher): each teacher teaches one subject (teacher → subject), and each student has one teacher per subject. The table is in 3NF but not BCNF, because teacher isn't a key yet determines subject. Splitting into teacher_subjects(teacher, subject) and student_teachers(student, teacher) fixes it.

Words you’ll hear

Functional dependency
X → Y: rows with the same X always have the same Y.
Superkey / candidate key
Columns that identify rows uniquely / a minimal such set.
BCNF
Every determinant of a non-trivial dependency is a superkey.
Multi-valued dependency (4NF)
Two independent lists of facts about one key stored in one table.

Visual diagram

Loading interactive diagram

Theory & example queries

How BCNF differs from 3NF

3NF says every non-key attribute depends on the key and nothing else, but it permits a dependency X → Y where Y is a prime attribute (part of some candidate key) even if X isn't a key. BCNF closes that gap: if any set of columns determines another column, it must be a superkey.

The difference only shows up when a table has overlapping candidate keys, as in class_bookings above. There, teacher → subject causes the familiar anomalies: a teacher's subject is repeated for each student, and changing it means updating many rows. The BCNF fix is to put teacher → subject in its own table.

The decompositionQuery example
1Input dataStart from the source rows or state that the statement sees.
This statement works with the current schema, configuration, or database state rather than a row dataset. The command still follows the same input → query → result flow.
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1CREATE TABLE teacher_subjects (2  teacher text PRIMARY KEY,3  subject text NOT NULL4);56CREATE TABLE student_teachers (7  student text,8  teacher text REFERENCES teacher_subjects (teacher),9  PRIMARY KEY (student, teacher)10);
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Choose the target

Identify the table or database object the statement will modify.

1/10
3OutputInspect the representative rows, affected-row count, plan, or command status.
Expected output
CREATE TABLE CREATE TABLE

Note: Representative PostgreSQL-style command statuses; both statements succeed when their referenced name space and constraints are valid.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

Key takeaway: BCNF: every determinant is a superkey; it differs from 3NF only with overlapping keys.

The trade-off, and 4NF / 5NF

A BCNF decomposition is always lossless (joining the parts gives back the original rows), but it isn't always dependency-preserving. After the split above, the rule "a student has one teacher per subject" spans two tables, so no single key enforces it; you'd need a trigger or application check. That's why designers sometimes stop at 3NF deliberately.

4NF handles multi-valued dependencies: employee_skills_languages(employee, skill, language) stores every combination of an employee's independent skills and languages, so adding one language means adding a row per skill. Split it into employee_skills and employee_languages. 5NF addresses join dependencies, which are rare in practice; most production schemas aim for 3NF or BCNF.

A 4NF fix

Instead of employee_skills_languages(employee, skill, language) with 3 skills × 2 languages = 6 rows, store employee_skills(employee, skill) (3 rows) and employee_languages(employee, language) (2 rows).

Key takeaway: BCNF can cost a dependency; 4NF separates independent lists.
Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Analysis

List the dependencies

Write down every functional dependency the business rules imply, such as teacher → subject.

Focus at this step

(student, subject) → teacher · teacher → subject

What to watch at this step
From
business rules
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

Boyce-Codd Normal Form (BCNF) tightens 3NF: for every functional dependency X → Y in a table, X must be a superkey (it must identify rows uniquely). 3NF allows one exception, when Y is part of some candidate key, and BCNF removes it. 4NF goes further, removing independent multi-valued facts stored in one table, and 5NF deals with rare join dependencies.

Why it matters: Most well-designed schemas in 3NF are already in BCNF, but the cases where they differ are classic exam and interview questions, and they show you understand dependencies rather than memorising rules. The 4NF example (skills and languages in one table) also appears in real schemas.

When to reach for it

  • Database theory and normalisation questions
  • Reviewing tables with several candidate keys
  • Fixing tables that store every combination of independent lists

When to avoid or be careful

  • Decomposing for BCNF without checking which rules can no longer be enforced
  • Storing independent lists in one table (skills × languages)
  • Chasing 5NF in everyday application design

3NF vs BCNF vs 4NF

3NF
Best for: The practical target for most transactional schemas

Strengths: Removes most redundancy; always dependency-preserving.

Watch out: Allows rare anomalies with overlapping candidate keys.

BCNF
Best for: Tables with overlapping candidate keys

Strengths: Removes all redundancy from functional dependencies.

Watch out: May split a rule across tables so no key enforces it.

4NF
Best for: Tables mixing independent multi-valued facts

Strengths: Stops combinatorial row explosion.

Watch out: More tables; rarely needed if the ERD is clean.

Interview signals & numbers to know

When this topic comes up

  • “What's the difference between 3NF and BCNF?”
  • “Is this table in BCNF?”
  • Overlapping candidate keys
  • Multi-valued dependencies
  • Normalisation theory

Benchmarks & rules of thumb

BCNF -
every determinant is a superkey
3 × 2 = 6 -
rows for 3 skills and 2 languages in a non-4NF table
3NF / BCNF -
typical production targets

Common mistakes & follow-ups

Common interview mistakes

  • Saying any table in 3NF is automatically in BCNF.
  • Splitting for BCNF and silently losing the rule that a student has one teacher per subject.
  • Combining employees' skills and languages in one table and multiplying rows.

Likely interviewer follow-ups

  • Give an example of a table that's in 3NF but not BCNF.
  • Is a BCNF decomposition always dependency-preserving?
  • What problem does 4NF solve?
Interview tip: Have the student-subject-teacher example ready, explain why teacher → subject breaks BCNF, and mention the dependency-preservation trade-off. That's the complete textbook answer.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Boyce-Codd Normal Form (BCNF) & Higher Normal Forms with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
Third Normal Form (3NF): Eliminating Transitive Dependencies
Next topic
Strategic Denormalization for Read-Heavy Analytical Workloads