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

Preview

DA 1.14: Tidy tables: normal forms

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

Change one name, fix it everywhere

A library sheet lists the author "Ana Lee" on 200 rows. Ana gets married and changes her name. Someone must change 200 rows.

Miss one and the sheet disagrees with itself. If the author were stored once, one change would fix everything. There is a set way to arrange tables to do that.

Key words

WordWhat it meansExample
NormalisationArranging tables so each fact is stored once.Author name in one place
Relational databaseA database that keeps data in linked tables.Members, books and loans
Primary keyA field that identifies each row in a table.member_id
Foreign keyA field that holds the primary key of another table, to link them.member_id in loans
Unnormalised formA table with repeated groups and mixed facts. Short name: UNF.A loan sheet
AtomicHolding only one value in a cell.One book per cell
DependencyWhen one field is decided by another field.A title is decided by its book id

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can take a table from unnormalised form to third normal form and say what each step fixes.

Starter: what you already know

Have a go

Starter: what you already know

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

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Unnormalised form: the loan sheet

membermember_namebooksauthors
1SamMaps, RiversAna Lee, Max Cho
2JoMapsAna Lee

The cells students fill in are left blank in this preview.

The three steps

First normal form (1NF): every cell holds one value, and there are no repeating groups. Split "Maps, Rivers" into separate rows.

Second normal form (2NF): every other field depends on the whole key, not part of it. Book facts move to a books table.

Third normal form (3NF): fields depend on the key and nothing else. Member facts move to a members table.

Try it: join the tables back

Code: sql
select m.member_name, b.title, l.loan_date
from loans l
join members m on m.member_id = l.member_id
join books b on b.book_id = l.book_id
order by l.loan_date;

-- Try it: add b.author to the list.

The lesson goes on

3 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.