5. Normalisation: 1NF to BCNF and 4NF, and when to denormalise
Normalisation removes redundancy by splitting tables so that every fact is stored once, in the one place it depends on. Functional dependencies say where that is; the normal forms are the rules; denormalising is copying on purpose, when reading speed is worth the risk.
The clip starts from a broker's spreadsheet of policies: one row per policy, with lists of drivers and coverages in single cells. First normal form gives every cell one value. Second normal form moves out what depends on only part of the key: policy details and coverage names. Third normal form moves out what depends on another non-key column: the customer's name and region, and the product's line. Boyce-Codd normal form splits a table where a broker determines the line but is not a key. Fourth normal form separates drivers and coverages, two independent lists. Each split can be joined back without losing a row.
The intuition: every fact in one place
A broker sends Harbour Mutual a spreadsheet of new policies: one row per policy, with the customer's name and region, the product and its line, a cell listing the drivers and another listing the coverages. It is easy to read and hard to keep right.
Anna Visser has three policies, so her name and region appear three times. When she moves, someone updates two rows and forgets the third: now the sheet says she lives in two regions. That is an update anomaly. A new product cannot be recorded until someone buys it, because every row needs a policy: an insert anomaly. Delete the only policy on a product and the product's line disappears with it: a delete anomaly.
All three come from one cause: a fact (Anna's region, a product's line) is stored in rows that are about something else (a policy). The cure is to store each fact once, in a table about the thing it describes, and to link the tables by keys. Normalisation is the method for finding where each fact belongs.
The theory: functional dependencies and the normal forms
A functional dependency X → Y holds in a table when any two rows that agree on the columns X must agree on the columns Y. customer_id → region holds: one customer, one region. It is a rule about every possible row, decided by the business, not a pattern found in today's data. The data can only refute a dependency, by showing two rows that break it.
SELECT
(SELECT COUNT(*) FROM (SELECT customer_id FROM customers GROUP BY customer_id
HAVING COUNT(DISTINCT region_id) > 1) v) AS customer_id_violations,
(SELECT COUNT(*) FROM (SELECT name FROM customers GROUP BY name
HAVING COUNT(DISTINCT region_id) > 1) v) AS name_violationsOn the seed, 0 customers break customer_id → region_id, as a key must. 2 names belong to customers in more than one region: two different people share a name, so a name does not determine a region and cannot be used as a key.
Dependencies follow from one another by three rules, Armstrong's axioms: reflexivity (a set determines its own subsets), augmentation (if X → Y then XZ → YZ) and transitivity (if X → Y and Y → Z then X → Z). The closure of a set of columns is everything it determines under these rules; a candidate key is a minimal set whose closure is every column. A column that belongs to some candidate key is prime.
Every split must be lossless: joining the parts gives back exactly the original rows, no fewer and no extra. Splitting a table into two is lossless when the columns they share form a key of at least one part. A split is dependency-preserving when every dependency can still be checked within a single table. A 3NF design that is both lossless and dependency-preserving always exists; a BCNF one may have to give up dependency preservation, as the broker example shows.
Beyond 4NF, fifth normal form deals with tables that can only be rebuilt by joining three or more parts, and sixth normal form, used for temporal data, gives each changing attribute a table of its own. In practice, designers aim for 3NF or BCNF and check for independent lists (4NF).
When to denormalise. Normalising optimises for writing: each fact changes in one place. Reading then needs joins. Denormalising copies facts on purpose to make reading simpler or faster: a star schema's dimensions (page 6) repeat a product's line on purpose; a reporting table stores precomputed totals; an invoice keeps the customer's address as it was on the day, because that copy is a different fact (the address at the time) and must not change. Denormalise when the data is read far more than it is written, when the copies are refreshed by a process you control, and when the normalised model still says which copy is the truth.
Why it matters
Harbour Mutual copies customer details from the CRM into the policy system and the warehouse every night. When one copy fails or is edited by hand, the same customer has two addresses and nobody can say which is current. Each copy was right on the day it was written; the design let them drift.
Normalisation is also a way of asking the business the right questions. "Can a broker sell more than one line?" decides whether a table is in BCNF. The answer is a business rule, and the model records it.
Where it goes wrong
- Dependencies guessed from data. A column that looks dependent in today's rows may not be by rule; ask the business.
- Normalising an analytical model to death. A report that needs twelve joins to show one number is a sign the reading side needs a dimensional model.
- Denormalising without an owner. Copies made "for performance" with no process to refresh them become the next anomaly.
- Lossy splits. Splitting on columns that are not a key of either part invents rows when the parts are joined again.
- Lists in a cell. A comma-separated value, or a JSON array, used where a child table belongs breaks 1NF, however modern the storage.
Check yourself
Choose an answer to each question, then press Check.
Sources
The works this page draws on, summarised in its own words rather than quoted. Read them for the full argument.
- E. F. Codd, "Further Normalization of the Data Base Relational Model" (1971) and "Recent Investigations into Relational Data Base Systems" (1974)Functional dependencies and the second and third normal forms, then Boyce-Codd normal form with Raymond Boyce.
- R. Fagin, "Multivalued Dependencies and a New Normal Form for Relational Databases", ACM Transactions on Database Systems 2(3), 1977Multivalued dependencies and fourth normal form.
- W. W. Armstrong, "Dependency Structures of Data Base Relationships", IFIP Congress, 1974The axioms from which all functional dependencies follow.
- W. Kent, "A Simple Guide to Five Normal Forms in Relational Database Theory", Communications of the ACM 26(2), 1983The normal forms in plain words, with "the key, the whole key, and nothing but the key".
- C. J. Date, An Introduction to Database Systems, 8th edition (Addison-Wesley, 2003)Lossless decomposition, dependency preservation, and fifth and sixth normal forms.
Practise it
The chapters that put this theory to work on Harbour Mutual and Kestrel:
The tools to try it in:
- Model studio · Draw conceptual, logical and physical models, generate DDL for PostgreSQL, Spark SQL and T-SQL, and run it on Harbour Mutual's data in your browser.
Terms taught here: NormalisationNormal formFunctional dependencyDenormalisation