drawDB blog
Guides to database schema design, data modeling and SQL for PostgreSQL, MySQL, SQLite, SQL Server and Oracle. Every post is built on real schemas from the drawDB schema gallery, so you can open what you read in the editor and export the SQL. Also available as an RSS feed.
· 9 min read
How to design an idempotency keys table for payment APIs and webhooks
The idempotency_keys table, the race-free claim, and when a unique column or a processed-events table is enough. Tested SQL, plus what 100 real schemas do.
schema-designpostgresqlpaymentsapi-design· 8 min read
Enum, lookup table or CHECK constraint: how to store a status column in SQL
567 status columns in our 100-schema gallery, zero native enums. When a CHECK constraint, an ENUM or a lookup table wins, with the DDL for six databases.
schema-designpostgresqlmysqldata-modeling· 8 min read
How to store a user-reorderable list in SQL: integer positions, fractional keys or a linked list
75 hand-ordered lists in our 100-schema gallery, and the three ways they break: tied defaults, decimals that run out after 50 drags, and collation.
schema-designpostgresqlmysqldata-modeling· 8 min read
How do you generate an ER diagram from an existing PostgreSQL or MySQL database?
Four ways to reverse-engineer a live database into an ER diagram, and what came back when we round-tripped 87 schemas through a catalog query.
reverse-engineeringer-diagrampostgresqlmysqlrelationships· 8 min read
When should you split a table into a one-to-one relationship, and how do you enforce it?
Unique foreign key or shared primary key, which side holds it, NULLs under UNIQUE per dialect, and what 43 one-to-one links in our gallery got wrong.
relationshipsconstraintsprimary-keyspostgresqlsql-servernormalization· 9 min read
How to store a tree in SQL: adjacency list, materialized path, ltree or closure table
Every tree in our 100-schema gallery is a parent_id column. When that is enough, when to add a path or closure table, and the constraints most trees skip.
schema-designpostgresqldata-modelinghierarchies· 9 min read
How do you design a double-entry ledger in SQL?
Accounts, journal entries and postings that sum to zero, enforced by PostgreSQL at commit. Tested on PostgreSQL 16 and MySQL 8, with two gallery schemas.
ledgerfintechpostgresqlmysqlconstraintstriggers· 7 min read
How do you design a many-to-many relationship in SQL?
Composite key or surrogate id, the reverse index most junction tables miss, and what 169 junction tables in our gallery chose. Measured on PostgreSQL 16.
relationshipsjunction-tablesindexespostgresqlmysqlprimary-keys· 7 min read
Should you store an account balance or calculate it from transactions?
Append-only ledger plus a cached balance, written in one transaction. Tested on PostgreSQL 16, with how 18 balance-holding schemas in our gallery do it.
ledgerfintechpostgresqlmysqlconcurrencyconstraints· 7 min read
How to soft delete rows without breaking unique constraints in PostgreSQL, MySQL and SQLite
Partial unique indexes, generated columns and restore conflicts, tested on PostgreSQL 16, MySQL 8 and SQLite, with 32 soft-deleted tables from our gallery.
soft-deletepostgresqlmysqlsqliteindexesconstraints· 7 min read
Multi-tenant database design: shared tables, schema per tenant, or database per tenant
How to choose a multi-tenant database model, with schema rules measured on real SaaS schemas and PostgreSQL row-level security you can copy and test.
multi-tenancysaaspostgresqlrow-level-security· 8 min read
Database schema design best practices, measured across 100 schemas and 1,232 tables
We audited all 1,232 tables in the drawDB schema gallery: primary keys, naming, timestamps, money, ON DELETE rules and foreign key indexes, with fixes.
schema-designpostgresqldata-modelingindexes
