- Home
- Interview Questions
- SQL
- How does BCNF differ from 3NF, and why can BCNF decompositio…
Try answering first
In a real interview nobody shows you the answer. Think it through (or type it), then reveal the answers and rate yourself.
1 Answer
Short answer: 3NF allows a functional dependency X → A when X is a superkey or A is part of some candidate key; BCNF removes that exception and requires X to be a superkey for every non-trivial dependency. Converting to BCNF is always lossless, but it is not always dependency-preserving, so some rules can no longer be enforced by keys within a single table.
Detailed explanation
Both normal forms look at every non-trivial functional dependency X → A in a table. They differ in what they accept:
- 3NF: X must be a superkey, or A must be a prime attribute (part of at least one candidate key).
- BCNF: X must be a superkey. There is no exception.
So every BCNF table is in 3NF, but not the other way round. The gap only shows up when a table has multiple overlapping composite candidate keys. If a table has a single candidate key, or only single-column keys, 3NF and BCNF are effectively the same.
The key trade-off, which is the classic exam result:
- A 3NF decomposition that is both lossless and dependency-preserving can always be found.
- A BCNF decomposition is always lossless, but sometimes no BCNF design preserves all dependencies.
"Lossless" means joining the pieces back gives exactly the original rows. "Dependency-preserving" means each rule can be checked inside one table, typically with a primary key or unique constraint, without joining tables.
Example
Business rules for this table:
- Each teacher teaches exactly one subject.
- For each subject, a student has exactly one teacher.
student_subject_teacher(student, subject, teacher)
FDs: {student, subject} → teacher
teacher → subject
Candidate keys: {student, subject} and {student, teacher}Every column is prime, so the table is in 3NF. But teacher → subject violates BCNF, because teacher alone is not a superkey. You see the redundancy in practice: teacher T1's subject is repeated for every student T1 teaches.
The BCNF decomposition:
teacher_subject(teacher PRIMARY KEY, subject)
student_teacher(student, teacher, PRIMARY KEY (student, teacher))This is lossless, because the shared column, teacher, is the key of teacher_subject. But {student, subject} → teacher now spans two tables. Nothing stops a student from being assigned both T1 and T2 when both teach Maths.
One practical way to enforce the lost rule is to keep subject redundantly and guard it with a composite foreign key:
CREATE TABLE teacher_subject (
teacher VARCHAR(50) PRIMARY KEY,
subject VARCHAR(50) NOT NULL,
UNIQUE (teacher, subject)
);
CREATE TABLE student_teacher (
student VARCHAR(50),
teacher VARCHAR(50),
subject VARCHAR(50) NOT NULL,
PRIMARY KEY (student, teacher),
UNIQUE (student, subject),
FOREIGN KEY (teacher, subject)
REFERENCES teacher_subject(teacher, subject)
);How this works:
- The composite foreign key guarantees the copied subject always matches the teacher.
UNIQUE (student, subject)enforces one teacher per subject per student.
The other options are to stay in 3NF and accept the redundancy, or to enforce the rule with a trigger.
Common mistakes
- Defining BCNF as "3NF with no transitive dependencies". 3NF already handles those; the real difference is the prime-attribute exception.
- Using an example with a single candidate key. That table cannot show the difference, and interviewers notice.
- Claiming BCNF is always the better target. If decomposition loses a business rule you must enforce, 3NF is often the right engineering choice.
- Mixing up lossless join with dependency preservation. They are independent properties.
Follow-up questions
- How do you check whether a decomposition is lossless using the common attributes of the two tables?
- What is 4NF, and which kind of redundancy does it remove that BCNF does not?
- How would you find all candidate keys of a table using attribute closure?
Interview tip: Memorise one small overlapping-keys example like student-subject-teacher; drawing it on the whiteboard answers both halves of the question in under two minutes.
Reviewed by the Interview Questions editorial team · Last updated
How well did you know this?
Rate yourself to track progress, build your streak and get “didn't know” questions in your revision list.
Your Answer
More hard SQL questions
Related Questions
- What is the difference between a view and a materialized view, and when would you use each? · SQL · 1 ans
- What are insertion, update and deletion anomalies, and how does normalization prevent them? · SQL · 1 ans
- How do ON DELETE CASCADE, SET NULL and RESTRICT work, and when are cascades dangerous? · SQL · 1 ans
- How do you fetch the entire row with the highest salary in each department? · SQL · 1 ans
- What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column) in SQL? · SQL · 1 ans
- How does a recursive CTE execute step by step, and how do you stop it looping forever? · SQL · 1 ans
- Why can wrapping an indexed column in a function in WHERE make a query slow? · SQL · 1 ans
- Why does WHERE column = NULL return no rows, and how should you filter NULLs correctly? · SQL · 1 ans
🙋 Was this asked in your interview?
Which company? (optional — adds this question to the company's page)