Free database fundamentals tutorial
How a database is actually shaped
The SQL tutorial teaches you to write queries against a schema someone else designed. This one is about the schema itself — primary keys, foreign keys, normalization, and what an index costs — the conceptual half of an interview the query-language chapters don't cover. Every example runs live: several sections here run a real constraint violation on purpose, so you see the actual Postgres error instead of reading about it.
Sign in to track your progress across chapters.
Basic
4 chaptersWhat a table actually is, and the constraints that keep it honest.
- 01What a table really is5 minEvery column has a type, and the type is enforced, not decorative — see what happens when you fight it.
- 02Primary keys and uniqueness6 minPRIMARY KEY and UNIQUE both stop duplicates, but they disagree on NULL — and that difference is the whole point of having both.
- 03Foreign keys and referential integrity6 minA foreign key doesn't just document a relationship between tables — Postgres checks it on every insert, and blocks (or cascades) the delete that would break it.
- 04Constraints that encode rules6 minCHECK, DEFAULT and NOT NULL let the table itself refuse bad data, instead of trusting every piece of app code that ever inserts into it.
Intermediate
2 chaptersWhy data gets split across tables in the first place, and when not to.
- 05Normalization I: fixing repeating groups8 min1NF fixes a list hiding in column names — and the fix uncovers a second problem: the same customer fact copied onto every row that mentions them.
- 06Normalization II: 3NF, and when to denormalize8 minSplit the repeating fact into its own table, watch a second dependency hide one level deeper, then decide on purpose when duplication is actually fine.
Advanced
1 chapterWhat an index buys you, read straight off a real query plan.
Already comfortable with schema design? The SQL query tutorial and question bank are where the interview-style practice lives.