CIE AS & A Level Computer Science, section 8.1 (Database concepts)
What normalisation is
Normalisation is the process of organising tables to remove redundancy and avoid update problems, by splitting tables so each fact is stored once.
First Normal Form (1NF)
- Each field holds a single value (it is atomic), with no repeating groups.
- Each record is unique, and there is a primary key.
Second Normal Form (2NF)
- The table is in 1NF, and
- there are no partial dependencies: every non-key attribute depends on the whole primary key (this matters when the key has more than one field).
Third Normal Form (3NF)
- The table is in 2NF, and
- there are no non-key dependencies: no non-key attribute depends on another non-key attribute.
A common summary: every non-key attribute depends on "the key, the whole key and nothing but the key".
Worked example
Unnormalised: ORDER(OrderID, CustomerName, CustomerCity, Item1, Qty1, Item2, Qty2)
- 1NF: remove the repeating group (Item and Qty), so each order line is a record: ORDERLINE(OrderID, ItemCode, ItemName, Qty, CustomerName, CustomerCity). Key: (OrderID, ItemCode).
- 2NF: ItemName depends only on ItemCode, and CustomerName and CustomerCity depend only on OrderID (partial dependencies). Split:
- ORDERLINE(OrderID, ItemCode, Qty)
- ITEM(ItemCode, ItemName)
- ORDER(OrderID, CustomerName, CustomerCity)
- 3NF: CustomerCity depends on CustomerName, a non-key attribute. Split again. A name isn't a reliable key (two customers can share one), so a new key, CustomerID, is created for the CUSTOMER table:
- ORDER(OrderID, CustomerID)
- CUSTOMER(CustomerID, CustomerName, CustomerCity)
Why a table is not in 3NF
Explain by naming the dependency: "CustomerCity depends on CustomerName, which is not the key, so the table is not in 3NF".
Benefits
Less redundancy, fewer inconsistencies, and easier updates. A drawback is that data is spread across more tables, so queries need joins.
Common mistake: stopping at 1NF or normalising "by feel". Work through each normal form in order. Also, remember that 2NF is only an issue when the primary key is composite (more than one field).
Exam tip: for "explain why this is not in 3NF", name the non-key attribute and the other non-key attribute it depends on. In a design, show tables with primary and foreign keys marked.
Check yourself
What does 1NF require?
Each field holds a single value (no repeating groups) and each record can be identified by a key.
What is a partial dependency?
A non-key attribute depends on only part of a composite primary key.
What does 3NF remove?
Dependencies of a non-key attribute on another non-key attribute.