You now know the pieces — types, keys, joins, indexes, transactions, security. This closing chapter is the judgement that ties them together: turning a real-world problem into a schema that's correct, fast and maintainable, and the everyday habits of teams who run databases well.
From requirements to schema
A repeatable modelling process:
- List the entities (nouns): student, programme, batch, payment.
- Give each a table with a primary key and its own attributes.
- Model relationships: one-to-many via a foreign key; many-to-many via a junction table.
- Add constraints and the indexes your known queries will need.
-- A student takes many programmes; a programme has many studentsCREATE TABLE enrolments (student_id INT,programme_id INT,enrolled_on DATE,PRIMARY KEY (student_id, programme_id), -- composite PKFOREIGN KEY (student_id) REFERENCES students(id),FOREIGN KEY (programme_id) REFERENCES programmes(id));
Normalisation revisited
Aim for third normal form as a default: every non-key column depends on the key, the whole key, and nothing but the key. In practice that means no repeating groups, no duplicated facts, and lookup tables for repeated values. It keeps data consistent and updates cheap.
When to denormalise
Normalisation optimises for correct writes; sometimes reads matter more. Denormalisation — deliberately duplicating data (a cached student_count on programmes) — trades write complexity for read speed. Do it consciously, only when a measured read problem justifies it, and keep the copies in sync (often with a trigger).
Conventions & habits
Practice
Design a small schema for Albero from scratch: students, programmes, a many-to-many enrolments junction table, and payments. Apply sensible types, keys, constraints and indexes; normalise to 3NF; then identify one place you might consciously denormalise for read speed and how you'd keep it in sync. You've completed MySQL end to end.
Key takeaways
- 01Model entities as tables, relationships as foreign keys, and many-to-many as junction tables.
- 02Default to third normal form: no duplicated facts, lookup tables for repeated values.
- 03Denormalise consciously for measured read problems — and keep the duplicated data in sync.
- 04Hold conventions: snake_case, surrogate id keys, created_at/updated_at, utf8mb4, InnoDB.
- 05Track schema changes as versioned migration scripts in source control — never hand-edit production.
