# Schema Design and Normalization

> Structure tables to avoid anomalies, and know when deliberate denormalization pays off. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/schema-design-normalization
Last updated: 2026-11-28

Structure tables to avoid anomalies, and know when deliberate denormalization pays off.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [The Relational Model](https://www.internhack.in/roadmaps/tracks/backend/relational-model), [Writing SQL Queries](https://www.internhack.in/roadmaps/tracks/backend/sql-querying)

**Normalization** is the practice of organizing tables so each fact is stored in exactly one place. It prevents **anomalies**: updating a customer's address in one order row but not another, or being unable to store a product until someone orders it.

### The normal forms, practically

- **1NF**: each column holds one atomic value; no repeating groups or lists in a cell.
- **2NF**: in tables with composite keys, every non-key column depends on the whole key.
- **3NF**: non-key columns depend only on the key, not on other non-key columns. (If `zip` determines `city`, `city` does not belong in the orders table.)

For most applications, aiming for 3NF and then making deliberate exceptions is the right default.

### Denormalization

Sometimes you intentionally duplicate data for read speed or simplicity: storing a `comment_count` on posts, or copying the price onto an order line (which is actually correct, because the order must remember the price at purchase time). Denormalize with intent and keep the copies in sync through transactions, triggers or events.

### Practical design habits

- Name consistently (`snake_case`, singular or plural, pick one).
- Add `created_at` and `updated_at` to most tables.
- Decide on **soft deletes** (`deleted_at`) versus hard deletes up front.

You are ready to move on when you can take a messy spreadsheet-style table and split it into a normalized schema, then justify one deliberate denormalization.

## Key concepts

- **Update, insert and delete anomalies**
- **First, second and third normal form**
- **Deliberate denormalization**
- **Naming conventions**
- **Soft deletes vs hard deletes**
- **BCNF and higher forms**

## Mini project

Take a flat CSV of orders (customer name, address, product, price, quantity in each row) and normalize it into customers, products, orders and order_items with a migration script that moves the data.

## Check yourself

Why is copying a product's price into order_items not a normalization violation in practice?

## Free resources

- [Database normalization (Wikipedia)](https://en.wikipedia.org/wiki/Database_normalization) (Wikipedia)
- [PostgreSQL: Data Definition](https://www.postgresql.org/docs/current/ddl.html) (PostgreSQL)

Previous: [MySQL, SQLite and Other Engines](https://www.internhack.in/roadmaps/tracks/backend/other-relational-engines) · Next: [ORMs and Query Builders](https://www.internhack.in/roadmaps/tracks/backend/orms-query-builders)

## More in Storing Data Relationally

- [The Relational Model](https://www.internhack.in/roadmaps/tracks/backend/relational-model)
- [Writing SQL Queries](https://www.internhack.in/roadmaps/tracks/backend/sql-querying)
- [PostgreSQL](https://www.internhack.in/roadmaps/tracks/backend/postgresql)
- [MySQL, SQLite and Other Engines](https://www.internhack.in/roadmaps/tracks/backend/other-relational-engines)
- [Schema Design and Normalization](https://www.internhack.in/roadmaps/tracks/backend/schema-design-normalization)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
