Schema fundamentals that prevent the expensive-to-fix mistakes: keys, constraints, normalization, correct types, and indexing discipline.
0 downloads · Used by 1 stacks
Link back to this module from your own README.
[](https://markdowners.com/m/markdowners/database-design-basics)No discussions about this module yet.
Start a discussionSchema decisions are expensive to reverse once real data exists. Default to strict, explicit, and normalized — relax only with a specific reason.
NOT NULL to every column that must always have a value — application-layer validation gets bypassed by scripts, migrations, and future code paths the original author never imagined; the database is the last line of defense.UNIQUE constraints for real-world uniqueness rules (one profile per user, one slug per author), not just an application-level check — a race condition between two concurrent requests will slip past an app-only check.CHECK constraints to enforce value ranges and enums at the schema level for anything security- or billing-relevant, mirroring the application's validation rather than replacing it.ON DELETE policy (CASCADE, RESTRICT, or SET NULL) chosen deliberately per relationship — never leave it to the default, and never let orphaned rows silently accumulate.timestamptz (not naive timestamp) for anything that crosses timezones.numeric type only.text over fixed-length varchar(n) unless a real length constraint from the business exists; then enforce it with a CHECK, not the type alone.WHERE, JOIN, or ORDER BY on a frequently queried table — an unindexed foreign key turns cascading deletes and joins into full table scans as the table grows.
Comments (0)
Sign in to comment. Sign in
No comments yet. Be the first to add one.