MySQL Database

Relational Thinking and Table Design

Relational databases store facts once, in the right table, connected by keys. Good design prevents the update-anomaly chaos that spreadsheet-style data suffers.

Key Concepts

  • Tables have typed columns and rows of records; each table models one entity (students, courses)
  • PRIMARY KEY uniquely identifies each row — usually an AUTO_INCREMENT id
  • FOREIGN KEY columns reference other tables' primary keys, forming relationships
  • One-to-many: one category, many questions; many-to-many needs a junction table
  • Normalisation in one sentence: don't store the same fact twice

Try It Yourself

Design on paper the tables for a school: students, subjects and marks. Mark primary keys, foreign keys and the one many-to-many relationship.