Tables and Data Types
- Naming and shape. Good schemas read like the business: singular-fact columns, consistent names, one concept per table.
- Choosing types. The narrowest honest type wins: it validates data at the door and keeps indexes small.
- Constraints as truth. NOT NULL and CHECK constraints turn business rules into physics: bad rows become impossible, not unlikely.
Keys and Constraints
- Primary keys. A primary key uniquely names each row: usually a surrogate id the business never reuses.
- Foreign keys. A foreign key makes a relationship real: the database refuses an order pointing at a customer that does not exist.
- Unique constraints. A UNIQUE constraint enforces natural uniqueness: one account per email, guaranteed by the engine.
Normalisation and Relationships
- Normalisation. Normalisation stores each fact once: a customer’s address lives in one row, not copied onto every order.
- Update anomalies. Duplicated facts drift: the anomaly is updating one copy and not the others, then trusting both.
- Denormalising deliberately. Sometimes you copy data for speed: denormalisation is a documented trade, made after measuring, not before.
Before and after this level
- Before: Level 7: Data Modification: INSERT, UPDATE and DELETE, Upserts and Merge Patterns, Safe Data Changes.
- Next: Level 9: Transactions: ACID, Isolation and Concurrency, Locks, Deadlocks and Transaction Design.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does SQL Level 8: Schema Design cover?
Tables and Data Types, Keys and Constraints, Normalisation and Relationships: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 7: Data Modification, which covers INSERT, UPDATE and DELETE, Upserts and Merge Patterns, Safe Data Changes.