Founding rate: RM5 off Basic, forever — applied automatically. See pricing

Menu

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 chapters

What a table actually is, and the constraints that keep it honest.

  1. 01What a table really is5 minEvery column has a type, and the type is enforced, not decorative — see what happens when you fight it.
  2. 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.
  3. 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.
  4. 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 chapters

Why data gets split across tables in the first place, and when not to.

  1. 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.
  2. 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 chapter

What an index buys you, read straight off a real query plan.

  1. 07Indexes7 minAn index gives the planner a shortcut past every row — read the query plan to see it decide, on the same 100,000-row table, with and without one.

Already comfortable with schema design? The SQL query tutorial and question bank are where the interview-style practice lives.