Schema, Keys & Data Types
Cheat sheet · https://pcornel.dk/topic.php?topic=6087
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 topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -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
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Primary and foreign keys | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Constraints / NULL behavior | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Normalization concepts | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Common data types | The original bounded check succeeds in the same time window | Production 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