What are the key considerations when designing a database schema?
Instruction: List and explain the major factors to consider when designing a database schema.
Updated
Official answer
Start with the operations and facts the system must support. Define what each row represents, entity identity, relationships, optionality and business invariants before choosing indexes or storage layout.
For an order system, distinguish an order header from its lines. Give lines an identity such as (order_id, line_number), reference the appropriate product/customer records, and store transaction-time price/address facts separately from current catalog/contact values. Choose precise amount types, currency and timestamp semantics, NULL policies and deletion behavior.
Use supported uniqueness, foreign-key and check constraints for enforceable rules. Cross-row or concurrent invariants may need transactions and isolation beyond row-level checks. Model tenant ownership and the actual access paths; encryption does not replace authorization.
Then evaluate expected reads, writes, growth, indexes, partitioning and engine limits. Balance normalization against justified derived structures with explicit refresh rules. Plan migrations, historical backfills, retention and recovery.
Validate the design using sample queries and adversarial cases: duplicate identities, missing parents, concurrent writes, late corrections and schema upgrades with old/new application versions. A diagram and successful happy-path insert are not enough to demonstrate a complete schema.