Tables, keys and normalisation

Keys, constraints, indexes and the normal forms.

TermMeaning
Primary keyUniquely identifies each row
Foreign keyPoints to a row in another table
NOT NULLA value is required
UNIQUENo duplicates allowed
IndexSpeeds 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.

โ† Changing dataSQL quick reference โ†’