Design relational tables with constraints and keys
8 steps · about 3 h 15 min · Beginner
- Turn entities into typed tables (tutorial, PostgreSQL Global Development Group, 25 min)
Start with columns and types that represent the facts the database must store.
- State row rules as constraints (reference, SQLite Consortium, 40 min)
NOT NULL, CHECK and UNIQUE rules reject invalid data consistently for every writer.
- Connect tables with foreign keys (tutorial, PostgreSQL Global Development Group, 25 min)
Referential integrity prevents child rows from pointing at records that do not exist.
- Use defaults only for real defaults (reference, PostgreSQL Global Development Group, 15 min)
A default should express a valid omitted value rather than conceal missing required information.
- Evaluate bounded categorical values (reference, PostgreSQL Global Development Group, 20 min)
Compare an enum with a lookup table or check constraint before fixing the representation.
- Separate names with schemas (guide, PostgreSQL Global Development Group, 20 min)
Namespaces organise related objects and make name resolution an explicit design choice.
- Change related rows atomically (tutorial, SQLite Consortium, 25 min)
A transaction preserves cross-table rules when one logical action needs several statements.
- Evolve the schema in controlled steps (guide, PostgreSQL Global Development Group, 25 min)
Practise adding and validating rules without treating a production schema as disposable.