Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 4.3 (12 of 12): Normalisation to third normal form

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

55 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
FormA class group in a UK school. A tutor is the teacher who looks after one form.12B
NormalisationOrganising tables so each fact is stored once.
DatabaseAn organised store of data that programs can search and change.
Primary keyA field that is different in every row. It finds one row.
Foreign keyA field that holds the primary key of a row in another table.
RedundancyThe same fact stored more than once.
Repeating groupSeveral 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Start: the unnormalised table

OrderCustomerFormTutorItems
1Aisha12BMs KhanHoodie 25 pounds (quantity 1), Cap 8 pounds (quantity 2)
2Ben10AMr LeeCap 8 pounds (quantity 1)
3Sam12BMs KhanHoodie 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

OrderItemPriceQuantityCustomerFormTutor
1Hoodie251Aisha12BMs Khan
1Cap82Aisha12BMs Khan
2Cap81Ben10AMr Lee
3Hoodie251Sam12BMs 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Step 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

TableFieldsKey
ORDEROrder, Customer, Form, TutorOrder
ITEMItem, PriceItem
ORDER_ITEMOrder, Item, QuantityOrder + 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Step 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

TableFieldsKeyForeign keys
FORMform_id, tutorform_idNone
CUSTOMERcustomer_id, name, form_idcustomer_idform_id
ITEMitem_id, item_name, priceitem_idNone
SHOP_ORDERorder_id, customer_idorder_idcustomer_id
ORDER_ITEMorder_id, item_id, quantityorder_id + item_idorder_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

Code: sql
-- 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.

Code: sql
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.