Q&A-1Explain normalisation through third normal form with a worked example.
Answer
Normalisation is a formal way of saying "store each fact once". Each normal form removes one way a table can hold the same fact in two places. I'll take one table through 1NF, 2NF and 3NF and show what each step actually removes.
Assume a single relational database, no deliberate denormalisation for read performance, and that we care about update anomalies rather than query speed.
Starting point. An order table where each row carries the customer's details and the items are crammed into one cell:
| order_id | customer_id | customer_email | customer_city | items |
|---|---|---|---|---|
| 1001 | C-77 | ada@example.com | Lisbon | 'SKU-1 x2, SKU-9 x1' |
| 1002 | C-77 | ada@example.com | Lisbon | 'SKU-1 x1' |
| 1003 | C-91 | bo@example.com | Porto | 'SKU-9 x3' |
1NF: every column holds a single value from its domain; no repeating groups. items breaks it: you cannot index, constrain or join it without string surgery, and a SKU containing a comma corrupts the row. Split to one row per item, key (order_id, sku):
| order_id | sku | qty | unit_price_paid | customer_id | customer_email | customer_city |
|---|---|---|---|---|---|---|
| 1001 | SKU-1 | 2 | 19.99 | C-77 | ada@example.com | Lisbon |
| 1001 | SKU-9 | 1 | 4.50 | C-77 | ada@example.com | Lisbon |
| 1002 | SKU-1 | 1 | 19.99 | C-77 | ada@example.com | Lisbon |
| 1003 | SKU-9 | 3 | 4.50 | C-91 | bo@example.com | Porto |
2NF: every non-key column depends on the whole key, not part of it. qty and unit_price_paid depend on (order_id, sku). customer_id, customer_email and customer_city depend only on order_id: a partial dependency. Split into orders(order_id, customer_id, customer_email, customer_city) and order_items(order_id, sku, qty, unit_price_paid).
3NF: no non-key column depends on another non-key column. In orders, customer_email and customer_city depend on customer_id, which is not the key. That is a transitive dependency. Split again:
customers(customer_id, email, city), orders(order_id, customer_id), order_items(order_id, sku, qty, unit_price_paid).
What the last step bought. Ada changes her email. Before, that is an UPDATE across every order row she owns: 2 rows in the starting table, 3 after 1NF, 2 in orders after 2NF. After 3NF it is one row in customers. The failure mode is not the extra writes; it is that a partial update leaves C-77 with two different emails and nothing in the schema says which is right. The database is self-contradictory and no constraint catches it.
The trap. unit_price_paid stays on order_items even though products has a price. The price paid is a fact about this order line; the current price is a fact about the product. Moving it would be wrong.
BCNF tightens 3NF: every determinant must be a superkey. It differs only when candidate keys overlap. enrolment(student, subject, teacher) with {student, subject} → teacher and teacher → subject: candidate keys are {student, subject} and {student, teacher}. teacher → subject has a non-superkey determinant, but subject is prime, so 3NF permits it and BCNF does not.
The trade. Normalisation makes update anomalies structurally impossible and costs joins at read time. A join is a performance problem you can measure and fix; inconsistent data is a correctness problem you often cannot detect.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.