Pcornel
Databases

Schema, Keys & Data Types

Cheat sheet · https://pcornel.dk/topic.php?topic=6087

Back to the Topic

Answer

Schema design defines tables, columns, data types, primary keys, foreign keys and constraints that keep data valid.

Remember

Every table needs a primary key. Use foreign keys and NOT NULL/CHECK constraints to let the database enforce rules. Choose types that fit the data (not text for everything).

First checks

  • \d <table> — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

schema → constraints enforced on every write → valid data

Where it usually breaks

Common problems are weak/missing keys, unexpected NULL semantics, lossy numeric/string conversions, incompatible collations/encodings, foreign-key failures from orphaned data and schema changes that rewrite large tables or block traffic.

Schema, Keys & Data Types verification boundary matrix

BoundaryInspectHealthy interpretationDo not infer
IntentPrimary and foreign keysIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeConstraints / NULL behaviorOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateNormalization conceptsIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeCommon data typesThe original bounded check succeeds in the same time windowProduction correctness outside this scope

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6087

Confirmation

Confirm action

Continue?