By Kevin McAleer, 7 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to state the Boyce-Codd rule, recognise a table that breaks it, and split that table so it complies.
Third normal form catches most design problems. Boyce-Codd normal form (BCNF) closes a small gap that remains, and it appears when a table has more than one way to identify a row. It is a stricter cousin of 3NF, sometimes called “3.5NF”.
Some columns determine others: knowing robot_id tells you the robot’s name. We write that as robot_id -> name, and call it a functional dependency.
BCNF: whenever one set of columns determines another, the determining columns must be able to identify the whole row on their own (a candidate key).
In plain words: if a column can decide the value of another column, it had better be a key. Almost all well-designed tables already follow this, which is why the problem cases feel a bit contrived.
The workshop runs tool sessions. Each builder books a tool, and each tool is taught by one mentor. The rules of the club:
CREATE TABLE tool_sessions (
builder TEXT,
tool TEXT,
mentor TEXT,
PRIMARY KEY (builder, tool)
);
INSERT INTO tool_sessions VALUES
('Kev', 'soldering', 'Ada'),
('Sam', 'soldering', 'Ada'),
('Kev', '3d printing', 'Grace'),
('Jo', '3d printing', 'Grace');
The key is (builder, tool), and that determines the mentor. This table is in 3NF. But rule 2 gives us another dependency, mentor -> tool, and mentor alone is not a key, because Ada appears in several rows. That breaks BCNF.
flowchart LR
A["builder + tool"] -->|"determines"| C["mentor"]
C -->|"determines (but is not a key)"| B["tool"]
Ada switches from soldering to laser cutting. We try to record that for one row:
UPDATE tool_sessions SET tool = 'laser cutting'
WHERE mentor = 'Ada' AND builder = 'Kev';
SELECT * FROM tool_sessions ORDER BY builder, tool;
builder tool mentor
------- ------------- ------
Jo 3d printing Grace
Kev 3d printing Grace
Kev laser cutting Ada
Sam soldering Ada
Now Ada teaches laser cutting for Kev and soldering for Sam, which contradicts rule 2. The table let us store a state that should be impossible, because the fact “Ada teaches X” is written in every one of her rows.
Put the data back before we fix the design:
DELETE FROM tool_sessions;
INSERT INTO tool_sessions VALUES
('Kev', 'soldering', 'Ada'),
('Sam', 'soldering', 'Ada'),
('Kev', '3d printing', 'Grace'),
('Jo', '3d printing', 'Grace');
Give the mentor -> tool fact its own table, where mentor is the key. Then keep only who booked which mentor:
CREATE TABLE mentors (
mentor TEXT PRIMARY KEY,
tool TEXT NOT NULL
);
CREATE TABLE bookings (
builder TEXT NOT NULL,
mentor TEXT NOT NULL REFERENCES mentors (mentor),
PRIMARY KEY (builder, mentor)
);
INSERT INTO mentors SELECT DISTINCT mentor, tool FROM tool_sessions;
INSERT INTO bookings SELECT builder, mentor FROM tool_sessions;
INSERT ... SELECT copies rows straight from one table into another, which is a handy way to migrate data. Check the pieces:
SELECT * FROM mentors;
mentor tool
------ -----------
Ada soldering
Grace 3d printing
Now Ada’s change is one update, in one place:
UPDATE mentors SET tool = 'laser cutting' WHERE mentor = 'Ada';
SELECT b.builder, m.tool, m.mentor
FROM bookings AS b
JOIN mentors AS m ON m.mentor = b.mentor
ORDER BY b.builder, m.tool;
builder tool mentor
------- ------------- ------
Jo 3d printing Grace
Kev 3d printing Grace
Kev laser cutting Ada
Sam laser cutting Ada
Every one of Ada’s bookings now agrees. The join rebuilds the original view of the data whenever you want it.
| Question | 3NF | BCNF |
|---|---|---|
| Rule | Non-key columns depend only on the key | Every determining column set must be a key |
| Strictness | Allows a dependency whose target is part of a key | Allows no exceptions |
| Cost | Rarely loses anything | Can lose the ability to enforce a rule with a constraint |
The trade-off is in that last row. After our split, nothing stops one builder from booking two soldering mentors, whereas rule 1 said each tool only once per builder. BCNF removed a contradiction but made one rule harder to enforce. In practice, designers aim for BCNF and accept 3NF when a split would lose an important rule.
Teachers: this is the most abstract lesson in the course. Try the “who determines what” game on paper first: write each rule on a card, and have pairs mark which columns decide which. Students who struggle can safely stop at 3NF and move on, as BCNF is a refinement and nothing later depends on it.
Linus, who teaches laser cutting, and book Jo with him. Which tables do you change?soldering. Use the join from above.courses(room, hour, teacher) table has the rule that each teacher always uses the same room. Which dependency breaks BCNF, and how would you split the table?Why: Keys are rules about the real world, not patterns in a few rows.
FOREIGN KEY constraint failed when I insert into bookings.mentors first, as bookings points at it.Why: A booking can’t refer to a mentor who doesn’t exist yet.
INSERT ... SELECT DISTINCT for the lookup table, and check row counts with COUNT(*).DISTINCT, duplicate mentors cause a primary key clash. Without the copy, rows never arrive.Quick quiz 1 of 3
What does BCNF require?
Quick quiz 2 of 3
In tool_sessions, why does mentor -> tool break BCNF?
Quick quiz 3 of 3
What did splitting into mentors and bookings fix?
Now let’s learn to put one query inside another.
Comments