WeCodeAcademy

Normalisation: First and Second Normal Form

Normalisation is organising tables to remove repetition, so each fact is stored once and cannot disagree with itself.

First normal form (1NF): every cell holds one value, and there are no repeating columns. A column phones = '024..., 055...' or columns course1, course2, course3 break it. Fix: one row per value.

Second normal form (2NF): in a table whose key has several columns, every other column must depend on the whole key. If an order-lines table has key (order, product) but also stores the product name, the name depends on product alone. Fix: move the product name into a products table.

The example shows the repeated product name being fixed.

Examplepython
Open in editor »
Quick check

Why is it a problem to repeat a product's price on every order line?

Your turn: write the code

A table stores each student's course in three columns (c1, c2, c3). Print the number of rows the same data needs in a one-row-per-course table: 2 students with 3 courses each.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.