Data Modeling

Database Normalization Explained With a Simple Example

By SheetNode Editorial Team · · 4 min read

Anyone who has kept records in a spreadsheet knows how it goes. You start with one tidy table, then add columns, then copy the same customer details onto fifty rows. A month later, one customer changes their email and half the rows disagree with the other half.

Database normalization is the discipline that prevents this. It is a set of design rules for splitting data into tables so each fact lives in exactly one place. This article walks through the idea with one small example, with no formal math required.

The Messy Starting Point

Imagine a small shop that tracks orders in one table. Each row holds everything about a single order line.

order_id | customer_name | customer_email | product      | category | qty
1        | Amina Rahman  | amina@mail.test | Notebook     | Paper    | 3
1        | Amina Rahman  | amina@mail.test | Pen set      | Writing  | 1
2        | Joel Parker   | joel@mail.test  | Notebook     | Paper    | 5

This works until it does not. The email for Amina appears twice, so changing it means editing several rows. Notebook's category is repeated for every order. Delete the only order from a customer and you also lose the customer. These problems have names: update, insertion and deletion anomalies.

First Normal Form: One Value Per Cell

The first rule is simple. Every column holds a single, indivisible value, and every row can be told apart from the others.

A common violation is stuffing several items into one cell, such as a product column holding "Notebook, Pen set". That makes searching, counting and updating painful. The fix is to give each item its own row, as in the table above, and to have a clear key. Here the pair of order number and product identifies a row.

Our example already satisfies this rule, but it still repeats a lot of information. That is what the next steps address.

Second Normal Form: No Partial Dependencies

The second rule applies when a table has a key made of several columns. Every non-key column must depend on the whole key, not just a piece of it.

Look at our key, order and product together. The customer name and email depend only on the order, not on the product. The category depends only on the product, not on the order. Those are partial dependencies.

The cure is to split the table by what each fact is really about.

  • An orders table holds order number, customer name and customer email.
  • A products table holds product name and category.
  • An order_items table holds order number, product and quantity.

Now the category of Notebook is stored once. Changing it is one edit.

Third Normal Form: No Hidden Chains

The third rule removes dependencies between non-key columns. A column should depend on the key, the whole key and nothing but the key.

In the orders table, the customer email depends on the customer, and the customer depends on the order. That is a chain: order leads to customer leads to email. If a customer places ten orders, the email is stored ten times again.

So we pull customers into their own table.

  1. customers: customer_id, name, email.
  2. orders: order_id, customer_id, order date.
  3. products: product_id, name, category.
  4. order_items: order_id, product_id, quantity.

Each table now describes one kind of thing. The orders table points to a customer by identifier instead of copying their details. Those pointers are called foreign keys.

Seeing the Benefits

After these steps, the earlier problems disappear.

  • Changing a customer's email is a single update in one row.
  • A new product can be added before anyone has ordered it.
  • Deleting an order does not erase the customer or the product.
  • Typos are less likely, because each name is typed once and referenced by identifier.

To get the original view back, you combine tables with a join. A query that lists order number, customer name and product name simply links the four tables through their keys.

SELECT o.order_id, c.name, p.name AS product, i.quantity
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
JOIN order_items i ON i.order_id = o.order_id
JOIN products p ON p.product_id = i.product_id;

When to Stop, and When to Bend the Rules

Higher forms exist, such as Boyce-Codd normal form and fourth normal form, but third normal form is enough for most business applications. Going further rarely pays off for everyday systems.

Normalization is also not a law. Reporting databases, search indexes and caches often hold deliberately duplicated data because reading one wide table is faster than joining many. This is called denormalization. The sensible order is to normalize first, measure real performance problems and only then duplicate selectively, with a clear plan to keep copies in sync.

A Quick Checklist

Before finalizing a design, ask these questions.

  • Does each table describe exactly one kind of thing?
  • Is every fact stored in one place only?
  • Can I name the key of each table, and does every column depend on it?
  • Would changing one real-world fact require editing more than one row?

If the last answer is yes, something probably needs splitting.

Frequently Asked Questions

Is normalization always necessary?

Not always. Small throwaway datasets, analytics exports and read-heavy reporting tables can reasonably stay flat. For any system where records are created, edited and deleted over time, normalization saves you from inconsistent data.

Does normalization make queries slower?

It can add joins, but with proper keys and indexes joins are fast on well-designed databases. If measurements show a real bottleneck, you can denormalize a specific part afterward instead of starting with duplicated data.

What is the difference between a primary key and a foreign key?

A primary key uniquely identifies each row in its own table, such as the customer identifier in the customers table. A foreign key is a column in another table that stores that identifier to point back to the row, which links the tables together.

Related reading