Ms Khan changes her name
A school shop keeps one big table. Every order row has the customer's form tutor, Ms Khan, typed in again and again. There are 300 rows with her name.
Then Ms Khan changes her surname. Somebody changes 299 rows. One row is missed. Now the data says two different things.
Normalisation means organising tables so each fact is stored once. It fixes this problem.
Key words
| Word | What it means | Example |
|---|---|---|
| Form | A class group in a UK school. A tutor is the teacher who looks after one form. | 12B |
| Normalisation | Organising tables so each fact is stored once. | |
| Database | An organised store of data that programs can search and change. | |
| Primary key | A field that is different in every row. It finds one row. | |
| Foreign key | A field that holds the primary key of a row in another table. | |
| Redundancy | The same fact stored more than once. | |
| Repeating group | Several values put in one cell. | Hoodie, Cap |
| First normal form (1NF) | One value in every cell and no repeating groups. | |
| Second normal form (2NF) | In 1NF, and every field depends on the whole key. | |
| Third normal form (3NF) | In 2NF, and no field depends on another field that is not the key. |
The cells students fill in are left blank in this preview.
The trouble with one big table
When the same fact is stored many times, three bad things happen.
You waste space. You must change many rows for one change, and you can miss one. And you cannot store a fact on its own. You cannot add a new form tutor until a student orders something.
Normalisation fixes this in three steps.
Quick check: the problem
Have a go
Quick check: the problem
3 questionsStart: the unnormalised table
| Order | Customer | Form | Tutor | Items |
|---|---|---|---|---|
| 1 | Aisha | 12B | Ms Khan | Hoodie 25 pounds (quantity 1), Cap 8 pounds (quantity 2) |
| 2 | Ben | 10A | Mr Lee | Cap 8 pounds (quantity 1) |
| 3 | Sam | 12B | Ms Khan | Hoodie 25 pounds (quantity 1) |
The cells students fill in are left blank in this preview.
Step 1: first normal form
Look at the Items column. Order 1 has two items in one cell. This is a repeating group.
To reach 1NF, give each item its own row. Each cell holds one value. The key is now two fields together: Order and Item.
Result: 1NF
| Order | Item | Price | Quantity | Customer | Form | Tutor |
|---|---|---|---|---|---|---|
| 1 | Hoodie | 25 | 1 | Aisha | 12B | Ms Khan |
| 1 | Cap | 8 | 2 | Aisha | 12B | Ms Khan |
| 2 | Cap | 8 | 1 | Ben | 10A | Mr Lee |
| 3 | Hoodie | 25 | 1 | Sam | 12B | Ms Khan |
The cells students fill in are left blank in this preview.
Quick check: first normal form
Have a go
Quick check: first normal form
3 questionsStep 2: second normal form
The key is Order plus Item. Ask of every other field: does it need the whole key?
Price depends on the Item only. The Customer depends on the Order only. Quantity needs both.
To reach 2NF, move each fact to a table where it depends on the whole key.
Result: 2NF
| Table | Fields | Key |
|---|---|---|
| ORDER | Order, Customer, Form, Tutor | Order |
| ITEM | Item, Price | Item |
| ORDER_ITEM | Order, Item, Quantity | Order + Item |
The cells students fill in are left blank in this preview.
Check: where does it go?
Have a go
Check: where does it go?
3 questionsStep 3: third normal form
In ORDER, the key is Order. Customer depends on Order. But Form depends on Customer, and Tutor depends on Form.
These are facts about the customer and the form, not about the order. To reach 3NF, move each side fact into its own table. Leave a foreign key behind. Now Ms Khan is stored once. A name change is one edit.
Result: 3NF
| Table | Fields | Key | Foreign keys |
|---|---|---|---|
| FORM | form_id, tutor | form_id | None |
| CUSTOMER | customer_id, name, form_id | customer_id | form_id |
| ITEM | item_id, item_name, price | item_id | None |
| SHOP_ORDER | order_id, customer_id | order_id | customer_id |
| ORDER_ITEM | order_id, item_id, quantity | order_id + item_id | order_id, item_id |
The cells students fill in are left blank in this preview.
Match each rule to its normal form
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Join the 3NF tables back together
-- Which tutor must be told about each order?
SELECT shop_order.order_id, customer.name, form.tutor
FROM shop_order
JOIN customer ON shop_order.customer_id = customer.customer_id
JOIN form ON customer.form_id = form.form_id;
-- One change fixes every row: UPDATE form SET tutor = 'Ms Khan-Smith' WHERE form_id = '12B';
Make a free account to save your work and track your progress.
Write a query over the 3NF tables
Use the 3NF tables. Write a query that shows the customer name, the item name and the quantity for every line of every order. Sort by customer name, then by item name.
SELECT name FROM customer;Make a free account to save your work, or press Start lab to work through the whole lesson.
Normalise a club table to 3NF
A club keeps one table with these fields: Member, Year group, Tutor, Event, Event date, Event place. Each row is one member at one event. A tutor depends on the year group. The date and place depend on the event. Normalise it to 3NF. Finish the ERD: add the tables, the primary keys (PK) and the foreign keys (FK).
erDiagram
MEMBER {
int member_id PK
string name
}
%% Add YEAR_GROUP (year and tutor), EVENT (date and place) and ATTENDANCE (the link).
%% Add the foreign keys and the relationships.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Which step is it?
Have a go
Which step is it?
4 questionsExit quiz
Have a go