Designing a relational schema means turning a fuzzy domain—customers, orders, parts, bookings—into tables, columns, keys, and constraints that the database engine can enforce and that your application code can live with. The reliable method is to model the domain in plain language first, then apply normalization until anomalies disappear, then add constraints and indexes, and finally test the model against real queries and data volume. The key condition: design for the questions you must answer and the integrity rules you must guarantee, not for today's screen layout.
This guide walks through the whole sequence, including the trade-offs that decide whether you normalize to third normal form or deliberately denormalize, and the failure cases—composite-key mistakes, nullable foreign keys, and many-to-many tables without uniqueness—that cause most real-world schema pain.
Start with the domain, not the tables
Before any CREATE TABLE statement, write down three things: the entities the business talks about, the facts it must record about each one, and the rules that must never be violated. "A customer places zero or more orders; each order belongs to exactly one customer; an order line references one product and has a quantity greater than zero" is a design document. Do it in prose or a simple box-and-line sketch.
Every noun that has its own identity and lifespan is a candidate entity. Every attribute that depends on that identity is a candidate column. Every verb connecting nouns is a candidate relationship. Resist the urge to merge entities just because they share fields: a person and a company may both have "name" and "address," but mixing them into one table usually produces nullable columns and ambiguous meaning.
Keep a running list of the queries the system must support. A schema that answers order totals but not "which products never sold?" isn't done. The query list also tells you later where indexes are needed.
Give every table a stable primary key
Choose a primary key whose value never changes and whose uniqueness is guaranteed by the model, not by convention. Two common families:
Surrogate keys (auto-incrementing integers, UUIDs, or GENERATED ALWAYS AS IDENTITY values) are stable and let natural business identifiers like email addresses change without rewriting references. Natural keys (an ISO country code, a chemical registry number) are meaningful but only safe when the real-world identifier is genuinely immutable.
This is a false choice if you treat it as either-or: a surrogate primary key plus a UNIQUE constraint on the natural identifier is usually the strongest combination. The surrogate keeps foreign keys small and stable; the unique constraint keeps duplicates out.
A key is only as good as its uniqueness. If the "key" is a composite of (customer_id, product_id) on a table that allows a customer to buy the same product on two different days, you've chosen the wrong key—add the date or an order identifier.
Separate entities into tables and resolve relationships
Model one-to-many relationships by storing a foreign key on the "many" side. An order references one customer, so orders.customer_id holds the pointer. Do not store a list of order IDs in the customer row; that's the classic mistake of putting repeating data in one column.
Many-to-many relationships require an associative (junction) table. Students and courses need enrollments(student_id, course_id). This table is not overhead—it's where the relationship's own attributes live (enrollment date, grade, status) and where you enforce uniqueness so a student can't register twice for the same course.
One-to-one relationships are rarer and usually exist for optional extensions or sensitive data. Put the foreign key in the table that is optional or more tightly controlled, and make it unique so no second row can point at the same target.
Normalize in stages
Normalization isn't a mystical process; each normal form removes a specific kind of redundancy that causes its own kind of bug.
First normal form (1NF): atomic values. One cell holds one value. A phone_numbers column containing "555-1234, 555-9876" violates it. If a customer can have several phone numbers, that's a child table with one row per number.
Second normal form (2NF): no partial dependency. Every non-key column must depend on the entire composite key. Suppose an order_lines(order_id, product_id, quantity, product_name, product_price) table. Product name and price depend only on product_id, not on the full key, so a price change either gets duplicated across history or creates contradictory rows. Pull product data into a products table and keep order_lines holding order_id, product_id, quantity, and any price that was actually charged at the time of sale (which is a legitimate historical fact, not redundancy).
Third normal form (3NF): no transitive dependency. Non-key columns must depend on the key only. An employees table with department_id and department_name violates 3NF because department name depends on department ID, a non-key column. The fix—a departments table—also gives you one place to rename a department.
Boyce–Codd normal form (BCNF) goes slightly further in tables with multiple overlapping candidate keys; in practice, reaching 3NF and checking for BCNF issues in unusual composite-key tables is the normal stopping point.
Here's a compact illustration of a common violation and repair; the difference is easy to see.
| Problem | Violation | Fix |
|---|---|---|
| Product price repeated per order line | 2NF partial dependency | products table; order lines store the charged price separately |
| Department name in employees table | 3NF transitive dependency | departments table |
| Comma-separated phone numbers | 1NF non-atomic value | customer_phones child table |
| Duplicate enrollment rows | Missing uniqueness | UNIQUE(student_id, course_id) |
Normalization is not the goal; removing update, insert, and delete anomalies is the goal. A schema in 3NF lets you change a customer's postal code in one row, prevents the situation where you can't add an order because a product row must exist first, and prevents accidental deletion of the last order from erasing the only record of a customer.
Know when to denormalize deliberately
Strict 3NF is not always the right physical design. Reporting and read-heavy systems often benefit from a summary table, a materialized view, or a duplicated column that saves a join on every request. The discipline is that denormalization is a documented decision with an owner of the duplication.
If you duplicate customer_name onto orders for display, decide which copy is authoritative and how the other is kept in sync—usually by an application rule, a trigger, or a scheduled job. If sync isn't defined, you've reintroduced the anomaly you removed during normalization, only disguised as a performance choice.
Similarly, JSON columns inside otherwise relational tables can be reasonable for genuinely schema-flexible payloads (webhook bodies, feature flags). They become harmful when used to avoid modeling stable, queryable attributes you will filter and join on.
Add constraints that make invalid states unrepresentable
A schema isn't done when it holds the right data; it's done when the wrong data can't get in. The database should enforce basic rules even if application code has a bug, and constraints document the intended invariants for everyone who reads the schema later.
NOT NULL on every column whose absence would be meaningless. Defaults are not a substitute for a deliberate decision. CHECK constraints for ranges and enumerated states (quantity > 0, a status in a known list—unless the list is better represented as a lookup table with foreign keys). Foreign keys in every relationship, with an explicit decision on ON DELETE: restrict the deletion when orphans would be wrong; cascade only when the child data is genuinely subordinate; set null only when the relationship is optional. UNIQUE constraints on natural identifiers and on the columns that define a relationship's identity (for example, one booking per seat per showing).
The classic failure: a foreign key column that permits NULL in a context where the relationship is mandatory. A payments.order_id that can be null allows payments that belong to no order and undermines every join you write afterward. Make it NOT NULL.
Another is ON DELETE CASCADE applied broadly because it's convenient during development. Cascading deletes travel through your entire graph, and a single deleted account can silently remove years of records. Choose the behavior entity by entity.
Choose data types with intent
Data type choices rarely make headlines, but they cause long-running bugs. Give each column the type that matches its domain and its comparison behavior.
Money: a fixed-precision decimal type (for example, NUMERIC(12,2)), never floating point, because binary floats can't represent most decimal fractions exactly and will produce cent-level mismatches. Store the currency code alongside any amount that can be in multiple currencies. Dates: DATE for calendar dates, a timestamp with time zone for instants. "Midnight local" is not an instant and will misbehave across daylight saving transitions if you store it as a naive timestamp. Text: a length-bounded type or a documented maximum, so you don't discover oversized data through an application failure later. Identifiers: integers for internal keys; UUIDs where distributed generation matters, with awareness that random UUID primary keys have storage and index-locality costs versus sequential identifiers.
Keep units in the column name when they aren't obvious: weight_grams, duration_seconds. This is the cheapest documentation you will ever write.
Plan indexes from the queries, not from the columns
Indexes are a physical design choice driven by access patterns. For each important query, note the equality predicates and the range predicates and sort order. A composite index serves a query when its leading columns match the predicates in the right order; a "one index per column" habit wastes space and rarely serves composite queries.
The practical sequence: build the schema and constraints first, load representative data, run EXPLAIN on the workload, and add indexes where the plan shows expensive scans. Don't index every column up front. Each index imposes write cost and storage, and redundant indexes (for instance, a single-column index on a column that's already the leading column of a composite index) add maintenance with no steady benefit.
There's a subtle trade-off in uniqueness enforcement versus indexing strategy: unique indexes double as constraints, which is often the most efficient way to protect an invariant.
Test the schema with data before committing
Two tests catch most design errors before they reach production.
First, write a few representative queries and check that you can answer them without hacks. Can you list each customer's most recent order? Customers with no orders? Products never sold? Each requires a specific shape—LEFT JOINs, subqueries, or window functions—and if the join path is convoluted, your model may be missing a relationship.
Second, try to insert the wrong thing and confirm the database rejects it: a negative quantity, a duplicate order ID, an order referencing a nonexistent customer, a student enrolled twice. If any of these succeed, add the constraint.
Then sketch the data volume for a year or two. A UNIQUE on a long string column is fine for 10,000 rows and can be painful at scale if the value is truly large. A SELECT * with five child tables is a plan problem, but sometimes it reveals a missing index or an overnormalized join.
Version the schema and plan for change
Schemas evolve. The safe pattern is to treat schema changes as versioned migrations: each change is a numbered, reviewed script applied in order, with a matching way to reverse it if the deploy fails. Rename or drop columns in stages (add the new column, migrate code, remove the old one) so a rollback doesn't destroy data.
Some changes are cheap—adding a nullable column, adding an index on many databases. Others are expensive: changing a column's type, rebuilding a table, or adding a NOT NULL constraint to a large table without a default. Modern database engines offer patterns such as adding the constraint as NOT VALID and validating it separately, or creating indexes concurrently on systems that support it. What's supported varies by engine and version, so confirm the exact syntax and version behavior in your database's current documentation before scheduling a migration.
Reference workflow checklist
The following order keeps the steps dependent on one another. Treat it as a lead-in to execution, not a replacement for the reasoning above.
1: Collect requirements and query lists. Success check: every stakeholder question in your list maps to a planned table or join. Failure signal: a required report can't be expressed without a comma-separated column. 2: Identify entities, attributes, relationships, and rules. Success check: each rule is written as an assertion you can test with a constraint. 3: Assign primary keys and add uniqueness for natural identifiers. Failure signal: a key value that must change when a customer changes email. 4: Resolve relationships, adding junction tables for many-to-many. Success check: no repeating groups and no nullable foreign keys where the relationship is mandatory. 5: Apply 1NF, 2NF, and 3NF checks. Success check: every non-key column depends on the whole key and nothing but the key; inspect any table with multiple candidate keys against BCNF. 6: Make a deliberate denormalization decision, if any. Success check: a named owner and a sync mechanism for every duplicated value. 7: Add NOT NULL, CHECK, UNIQUE, and foreign-key actions. Success check: the invalid-insert tests from the previous section fail as intended. 8: Choose data types with units and precision in mind. Success check: money is decimal, instants carry time zone, and lengths are bounded. 9: Index against the query workload. Success check: representative queries use the intended indexes rather than full scans. 10: Test with representative volume and version the schema. Success check: migrations apply cleanly in a staging copy and the rollback path exists.
Stop and seek review from a senior database engineer or architect when the design involves regulated data, cross-system replication, or a migration of existing production data where a constraint cannot be validated without downtime. Those cases need a specialist, not a solo first pass.
A schema is a contract you'll live with for years. Getting the entities and keys right early, keeping constraints honest, and testing before you commit saves more effort than any optimization you'll apply afterward.