Tables, keys and normalisation
Keys, constraints, indexes and the normal forms.
| Term | Meaning |
|---|---|
Primary key | Uniquely identifies each row |
Foreign key | Points to a row in another table |
NOT NULL | A value is required |
UNIQUE | No duplicates allowed |
Index | Speeds up searching, at a small cost to writes |
Normalisation
- First normal form: each cell holds one value, with no lists inside a column.
- Second normal form: every column depends on the whole primary key.
- Third normal form: columns do not depend on other non-key columns.
The goal is to store each fact in one place, so it cannot go out of step. For example, keep department names in their own table and refer to them by id.