Courses / Databases for Backend Interviews / Chapter 8
Module 4 · The relational model and normalisation · Chapter 8 of 27
Normalisation: Anomalies, 1NF to BCNF, and When to Denormalise
Builds on Functional Dependencies: Closures, Candidate Keys and Minimal Covers. Next up: SQL Essentials: Tables, Changes, Queries, Joins, Subqueries and Views.
Part 1 · Update, insert and delete anomalies
One wide table, three problems
A housing society treasurer starts with one spreadsheet of maintenance bills, and every bill row repeats the flat, the owner and the owner's phone. It works until the first correction, and the problems it causes have names.
Normalisation is the process of splitting a table into smaller ones so that each fact is stored once. It is guided by the functional dependencies from the previous chapter. The thing it prevents is a modification anomaly: a surprising failure that appears when you insert, update or delete rows in a table that mixes several kinds of facts. There are three kinds, and the wide table below shows each of them.
The table maintenance has one row per flat per month. Its key is (flat_no, month). The dependencies that hold in the real world are flat_no → owner_id, owner_id → owner_name, owner_phone and (flat_no, month) → amount_due, paid_on. The first two say things about flats and owners, but the table stores them once per bill.
CREATE TABLE maintenance ( flat_no text NOT NULL, month text NOT NULL, owner_id int NOT NULL, owner_name text NOT NULL, owner_phone text NOT NULL, amount_due int NOT NULL, paid_on date, PRIMARY KEY (flat_no, month) ); INSERT INTO maintenance (flat_no, month, owner_id, owner_name, owner_phone, amount_due, paid_on) VALUES ('A-101', '2026-01', 7, 'Lakshmi Rao', '5550100111', 2400, '2026-01-04'), ('A-101', '2026-02', 7, 'Lakshmi Rao', '5550100111', 2400, '2026-02-02'), ('A-101', '2026-03', 7, 'Lakshmi Rao', '5550100111', 2400, NULL), ('A-102', '2026-01', 8, 'Raghav Pillai', '5550100222', 1800, '2026-01-09'), ('A-102', '2026-02', 8, 'Raghav Pillai', '5550100222', 1800, NULL), ('B-201', '2026-01', 7, 'Lakshmi Rao', '5550100111', 2000, '2026-01-05');