IntermediateData Modeling · 15 min · 12 challenges

Normalization

In 1970, IBM researcher Edgar Codd published the paper that introduced the relational model and the idea of a normal form. The problem it answered shows up in a parts-ordering file of that era, with one supplier's phone number typed onto 4,000 order records. The supplier changes numbers, and a clerk updates 3,988. Which number does the warehouse call? Normalization designs that question away.

Data Gets Out of Sync

Daily Life
Interviews

An online shop that sells coffee gear keeps every order in one wide table called orders_flat. Each row is one product on one order, and each row also carries facts about the customer and the product. Here are 4 of its rows and 5 of its columns.

order_idproduct_namelist_pricecustomer_idcustomer_email
1001Burr Grinder89.0017maya@oldmail.com
1001Paper Filters6.2517maya@oldmail.com
1014Pour-Over Kettle42.5017maya@oldmail.com
1015Paper Filters6.2522dev@patel.io
Customer 17 is Ruth Okafor. She has 3 rows, so her email is stored 3 times. She changes it to ruth@newmail.com, and the account page runs an update written back when the shop assumed one order per customer, so it targets her latest order only.
UPDATE orders_flat
SET customer_email = 'maya@newmail.com'
WHERE order_id = 1014
The statement succeeds and reports 1 row changed. The table now holds 2 different emails for customer 17, and no column says which is current. A query can count the damage.
SELECT
customer_id,
COUNT(DISTINCT customer_email) AS emails_on_file
FROM orders_flat
GROUP BY customer_id
HAVING COUNT(DISTINCT customer_email) > 1

It returns customer 17 with emails_on_file of 2. The shipping notice for order 1001 goes to an inbox Ruth no longer reads, while the receipt for order 1014 reaches her. Both features read the same table and got different answers.

Redundancy: one fact in many cells

A fact is one true statement about the business, such as: customer 17's email is ruth@newmail.com. Redundancy means a table stores that statement in more than one cell. Every extra copy is a cell that a future write can miss. The database cannot notice the miss, because each row is valid on its own.

A repeated value is a different thing from a repeated fact. Orders 1001 and 1014 both carry customer_id 17, and those are 2 separate facts: each says who placed that particular order. The email beside them is a single fact about customer 17, written out again. The test to carry through this lesson: if this fact changed in the real world, how many cells would need editing? Any answer above 1 means the table is redundant.

Order 1001's 2 rows also repeat who placed it. Second normal form returns to that.

Multiple Choice

A shipments table has one row per shipment and the columns shipment_id, warehouse_id, warehouse_phone and weight_kg. Warehouse 3 has sent 5,000 shipments. Which column stores a redundant fact?

3 ways the copies hurt

The 3 anomalies in the flat table
  • Update anomalySome copies change and others stay staleRuth's email is this case: 1 of her 3 rows was edited, and the table now contradicts itself.
  • Insert anomalyA fact has no row to live in yetLin Zhao signs up and has not ordered. Every row needs an order, so the table has nowhere to put her email.
  • Delete anomalyRemoving one fact destroys anotherOrder 1015 is Dev Patel's only order. Deleting that row after a cancellation erases the only copy of his email.
All 3 share one cause. The table mixes facts about customers, products and orders in the same row, so a write aimed at one kind of fact collides with the others.
Multiple Choice

The shop deletes the row for order 1015 after Dev cancels. A week later, marketing asks for Dev's email and no row has it. What happened?

Normalization: a ladder of tests

Normalization is the process of splitting a table until each fact is stored in exactly one place. It proceeds through normal forms, each a test that a table passes or fails. First normal form deals with cells that hold more than one value. Second and third normal form each remove one kind of repeated fact. The forms stack: each assumes the table already passes the one before it.
Keep the edit-count test close. Each normal form that follows is a sharper version of it, aimed at one particular shape of table.

First Normal Form (1NF)

Daily Life
Interviews

The shop arrived at orders_flat by repairing an earlier design. Version 1, orders_v1, kept one row per order and packed the products into a single text column.

order_idcustomer_iditems
100117Burr Grinder x1, Paper Filters x2
101417Pour-Over Kettle x1
101522Paper Filters x1
102031Paper Filters Holder x1

First normal form (1NF) asks 3 things of a table. Every row is identified by a primary key. Every cell holds a single value. No kind of value is spread across numbered columns. orders_v1 has a key and fails the second demand: the items cell for order 1001 holds 2 products and 2 quantities.

What a multi-value cell costs

The database sees items as one VARCHAR and knows nothing about the parts inside it. Ask how many orders included Paper Filters, and the only tool available is pattern matching.

SELECT
COUNT(*) AS orders_with_filters
FROM orders_v1
WHERE items LIKE '%Paper Filters%'

The query returns 3, and the true answer is 2. Order 1020 bought a Paper Filters Holder, and the pattern cannot tell a product from a longer name that contains it. Other questions fail harder. Total units of Paper Filters sold is 3, but SUM cannot reach a quantity buried in text. A foreign key cannot point from part of a string to a product, so a typo such as Paper Fliters is accepted without complaint.

Repeating groups: the same flaw in columns

Version 2, orders_v2, replaced the string with numbered columns.

order_iditem_1qty_1item_2qty_2
1001Burr Grinder1Paper Filters2
1014Pour-Over Kettle1NULLNULL

Each cell now holds one value, and the table still fails 1NF. item_1 and item_2 are a repeating group: one kind of fact spread across numbered columns. An order with 3 products needs a schema change. Finding Paper Filters means testing every item column, and that query grows with each column added.

SELECT
order_id
FROM orders_v2
WHERE item_1 = 'Paper Filters'
OR item_2 = 'Paper Filters'

The repair: one row per value

Both versions hide a one-to-many relationship inside a single row: one order has many products. The 1NF repair gives each product on an order its own row. Order 1001 becomes 2 rows. order_id alone no longer identifies a row, so the primary key becomes the composite (order_id, product_id).

order_idproduct_idproduct_namequantity
1001501Burr Grinder1
1001502Paper Filters2
1014503Pour-Over Kettle1
1015502Paper Filters1
1020504Paper Filters Holder1

This is orders_flat, shown without its customer columns. Products are now values the database can compare, join and add up.

SELECT
SUM(quantity) AS units_sold
FROM orders_flat
WHERE product_id = 502
The result is 3: 2 units from order 1001 and 1 from order 1015. The holder on order 1020 is product 504 and stays out of the total.

How small is a single value?

A value is single when no query needs a piece of it. 2026-03-14 09:30:00 contains a year and an hour, and a TIMESTAMP still counts as one value, because the type hands the database those parts. A full_name of Maya Okafor is one value for a shop that only prints it on labels. It becomes 2 values the day someone asks to sort customers by family name. The test for any column: do queries pull part of the cell out with string functions to filter, join or aggregate? If they do, the cell holds more than one value.

TIP
A table with no primary key also fails 1NF. 2 identical rows cannot be told apart, so no update or delete can target one of them.
Multiple Choice

Which table fails 1NF, for the reason given?

1NF made every value reachable with ordinary comparisons. It also multiplied the repeated facts: order 1001 now has 2 rows, so anything true of the whole order is written on both. The next 2 forms remove that repetition.

Second Normal Form (2NF)

Daily Life
Interviews

After the 1NF repair, orders_flat has one row per product per order and the composite primary key (order_id, product_id). Here it is with its order and product columns. customer_email is still in the table and waits for the next section.

order_idproduct_idquantityproduct_namelist_priceorder_datecustomer_id
10015011Burr Grinder89.002026-03-0217
10015022Paper Filters6.252026-03-0217
10145031Pour-Over Kettle42.502026-03-0917
10155021Paper Filters6.252026-03-1022
10205041Paper Filters Holder14.002026-03-1231

Functional dependency: what determines what

Column B is functionally dependent on column A when knowing A's value tells you B's value, with no exceptions. Write it A → B and read it as: A determines B. In this shop, product_id → product_name, because the catalog gives each product one name. The reverse can fail, since 2 products could share a name. A dependency is a rule about the business. Rows can disprove a suspected rule, and only someone who knows the business can confirm one: product 502 reading Paper Filters on every row is consistent with the catalog rule and cannot prove it.

Now ask of each non-key column: which part of the key do I need to know this?
ColumnDetermined byNeeds the whole key?
quantity(order_id, product_id)Yes
product_nameproduct_idNo
list_priceproduct_idNo
order_dateorder_idNo
customer_idorder_idNo

Only quantity needs both halves: how many Paper Filters were bought is a fact about one product on one order. The other 4 columns each show a partial dependency, which is a non-key column determined by only part of a composite key.

The 2NF rule

A table is in second normal form (2NF) when it is in 1NF and every non-key column depends on the whole primary key. Partial dependencies are where the repeated facts come from. order_date depends on order_id alone, so it is written once for every product on the order. product_name depends on product_id alone, so it is written once for every order that includes the product. The repair moves each such column to a table whose key is exactly the part it depends on.

orders
order_idPKBIGINT
order_dateDATE
customer_idBIGINT
customer_emailVARCHAR
order_items
order_idPKBIGINT
product_idPKBIGINT
quantityINTEGER
products
product_idPKBIGINT
product_nameVARCHAR
list_priceDECIMAL(10,2)

Each table now has one meaning per row: a row of orders is one order, a row of products is one product, and a row of order_items is one product on one order. Renaming product 502 edits 1 row in products, where before it edited every order line that mentioned it. A Milk Frother can sit in products at 24.00 before anyone buys it, and deleting order 1015 leaves Paper Filters in the catalog. No fact was lost: joining the 3 tables on their keys rebuilds every original row.

TIP
A table whose primary key is a single column cannot have a partial dependency, because a single column has no parts. If it passes 1NF, it passes 2NF. The 2NF test only applies when the key is composite.
Multiple Choice

enrollments has the primary key (student_id, course_id) and the non-key columns grade, student_name and course_title. Which columns break 2NF?

Which price belongs where?

list_price raises a question the dependency test can settle. Today's catalog price depends on product_id, so it lives in products. The price Ruth paid on order 1001 depends on the order and the product together, because a sale can make it differ from the catalog. A shop that reports revenue per order needs a unit_price_paid column in order_items. These are 2 different facts with similar names, and each goes where its dependency points.

Multiple Choice

The shop adds 2 columns: coupon_code, applied once to a whole order, and gift_wrapped, chosen separately for each product on an order. Where does each belong?

orders still carries customer_email beside customer_id. Its key is a single column, so 2NF has no further complaint. Ruth's stale email survives this split, and catching it takes one more test.

Third Normal Form (3NF)

Daily Life
Interviews

Here is orders after the 2NF split, with the email Ruth's update left behind.

order_idorder_datecustomer_idcustomer_email
10012026-03-0217maya@oldmail.com
10142026-03-0917maya@newmail.com
10152026-03-1022dev@patel.io
10202026-03-1231sam@riverbend.org

Rows 1001 and 1014 still disagree about customer 17. The table passes 1NF. Its key is the single column order_id, so it passes 2NF. The repeated fact arrives by a different route.

Transitive dependency: a chain through a non-key column

order_id determines customer_id, since each order has one customer. customer_id determines customer_email, since each customer has one email on file. So order_id reaches customer_email only by passing through customer_id. That chain, from key to non-key to non-key, is a transitive dependency. The email is a fact about the customer, stored in a table whose rows are about orders, so it repeats once for every order the customer places.

The 3NF rule

A table is in third normal form (3NF) when it is in 2NF and no non-key column depends on another non-key column. Every non-key column must describe the key directly. The test for each one: does some other non-key column in this table determine it? customer_email fails, because customer_id determines it. order_date passes, because no other column tells you when an order was placed.

The key, the whole key, nothing but the key
William Kent's 1983 summary: a non-key column must provide a fact about the key, the whole key, and nothing but the key. Read it as 3 checks. Having a key belongs to 1NF. Needing the whole key is 2NF. Depending on nothing but the key is 3NF.
The repair is the same move as in 2NF. Take the dependent column out and put it in a table keyed by the column that determines it.
customers
customer_idPKBIGINT
customer_nameVARCHAR
customer_emailVARCHAR
orders
order_idPKBIGINT
order_dateDATE
customer_idFKBIGINT
order_items
order_idPKBIGINT
product_idPKBIGINT
quantityINTEGER
products
product_idPKBIGINT
product_nameVARCHAR
list_priceDECIMAL(10,2)

Ruth's email is now 1 cell in customers. The update that opened this lesson changes 1 row, and every order she has placed or will place reads the new value through customer_id. Lin Zhao can exist as a customer before her first order. Dev's row survives the cancellation of order 1015.

Multiple Choice

employees has the primary key employee_id and the columns name, department_id and department_floor. Each department sits on one floor. Which diagnosis is right?

The rule reaches further than lookups such as an email. Any non-key column that other non-key columns determine fails it.
Multiple Choice

A rentals table has the key rental_id and the columns start_date, end_date and days_rented, where days_rented always equals the gap between the 2 dates. Why does it fail 3NF?

What 3NF costs

The shop went from 1 table to 4. Writes became cheap and safe: every fact has 1 home, so an update touches 1 row. Reads became longer. Units sold per customer email now takes 3 tables.
SELECT
c.customer_email,
SUM(oi.quantity) AS units
FROM order_items AS oi
JOIN orders AS o
ON oi.order_id = o.order_id
JOIN customers AS c
ON o.customer_id = c.customer_id
GROUP BY c.customer_email
For Ruth this returns ruth@newmail.com with 4 units: 1 grinder, 2 packs of filters and 1 kettle. The same question against the flat table would have split her total across 2 emails.

3NF also changes what past orders show. Joining orders to customers now returns each customer's current email on every order, past orders included, so order 1001 shows Ruth's new address even though its shipping notice went to the old one. If the shop needs to know where that notice was sent, the address is a fact about the order, and it belongs in orders as its own column.

Every split in this lesson followed one instruction. Find a column that describes something other than the table's key, and move it to the table that has that key.

Identifying Normal Form

Daily Life
Interviews
Normal forms are cumulative. A table is in 2NF only if it is also in 1NF, and in 3NF only if it is also in 2NF. Diagnosing a table means running the tests in order and stopping at the first failure. The table's normal form is the last test it passed.

The 4-step diagnosis

Run these in order
  • 1. Find the key. Every later test measures columns against it. A table with no key fails 1NF.
  • 2. Read the cells. A list inside a cell, or numbered columns such as phone_1 and phone_2, fails 1NF.
  • 3. Test the parts of the key. With a composite key, a non-key column determined by one part fails 2NF.
  • 4. Test the non-key columns. A non-key column determined by another non-key column fails 3NF.

A worked diagnosis

A gym stores class bookings in one table, class_bookings. The staff confirm 4 rules: a member has one name, a session is one class led by one trainer, a trainer has one name, and a member books a given session at most once.

member_idsession_idbooked_atmember_nameclass_nametrainer_idtrainer_name
83002026-05-04 18:02Ana RuizSpin4Kofi Mensah
93002026-05-04 19:15Tom BeckerSpin4Kofi Mensah
83112026-05-05 07:40Ana RuizYoga6Priya Nair

Step 1: the last rule makes (member_id, session_id) the key. Step 2: every cell holds one value, so 1NF passes. Step 3: member_name needs only member_id, and class_name needs only session_id. Those are partial dependencies, so the diagnosis stops here: class_bookings is in 1NF.

Repairing 2NF produces members, sessions and bookings, and each new table gets its own diagnosis. sessions(session_id, class_name, trainer_id, trainer_name) has a single-column key, so it passes 2NF. Step 4 finds trainer_id → trainer_name, so sessions is in 2NF and stops there. Move trainer names to a trainers table and all 4 tables reach 3NF.

Rules come from the business, evidence from the data

The diagnosis leaned on rules the gym staff stated. Column names suggest dependencies and cannot confirm them. Data can test a suspected rule, though: if A determines B, no value of A ever appears with 2 different values of B.
SELECT
trainer_id,
COUNT(DISTINCT trainer_name) AS names
FROM class_bookings
GROUP BY trainer_id
HAVING COUNT(DISTINCT trainer_name) > 1

Zero rows back means the data is consistent with trainer_id → trainer_name. Rows back mean one of 2 things: the rule is false, or the rule is true and the copies have already drifted apart. That second case is Ruth's email all over again, so the same query works as an audit of any wide table.

The Library's Loan SheetStep 1
>

A community library imports its paper loan sheet as one table. Each new requirement exposes a flaw. Pick the change that fixes the cause.

loans
loan_idBIGINTPKmember_idBIGINTmember_phoneVARCHARbook_titlesVARCHARdue_dateDATE

The librarian wants a count of how often each book is borrowed. `book_titles` holds text such as `Dune; Emma`. What do you change?

These 4 steps work on any table you inherit. Find the key, read the cells, test the parts of the key, test the non-key columns, and name the first test that fails.
PUTTING IT ALL TOGETHER

> A meal-kit subscription company moves its order spreadsheet into a database. Each row holds a subscriber, a delivery week, a comma-separated list of recipes, the subscriber's address and each recipe's calorie count. Within a month, support sees boxes going to old addresses and 2 different calorie counts for one recipe.

The recipe list in one cell fails 1NF. One row per recipe per delivery makes recipes countable and gives the table the key (delivery_id, recipe_id).
Calorie count depends on recipe_id alone, a partial dependency. Moving it to a recipes table removes the update anomaly behind the 2 calorie counts.
The address depends on subscriber_id, a non-key column of deliveries. That transitive dependency kept old addresses alive, and a subscribers table gives each address 1 home.
Running the 4-step diagnosis on every resulting table confirms each reaches 3NF, and a COUNT(DISTINCT) check per subscriber shows which addresses had already drifted.
If the company must know where a past box was shipped, that address is a fact about the delivery and gets its own column there.
KEY TAKEAWAYS
Redundancy means one fact stored in more than one cell. Test for it by asking how many cells an edit would touch.
Update, insert and delete anomalies share one cause: a single table holding facts about several different things.
1NF: a primary key, one value per cell, no numbered column groups. The repair is one row per value.
2NF: every non-key column needs the whole composite key. Move a partial dependency to a table keyed by that part.
3NF: no non-key column determines another. Move the dependent column to a table keyed by the column that determines it.
Diagnose in order and stop at the first failed test. Dependencies are business rules, and a COUNT(DISTINCT) query catches data that breaks them.

Store each fact in one place, and learn the 3 tests that show when a table stores it in several.

Category
Data Modeling
Difficulty
intermediate
Duration
15 minutes
Challenges
12 hands-on challenges

Topics covered: Data Gets Out of Sync, First Normal Form (1NF), Second Normal Form (2NF), Third Normal Form (3NF), Identifying Normal Form

Lesson Sections

  1. Data Gets Out of Sync

    Customer 17 is Ruth Okafor. She has 3 rows, so her email is stored 3 times. She changes it to ruth@newmail.com, and the account page runs an update written back when the shop assumed one order per customer, so it targets her latest order only. The statement succeeds and reports 1 row changed. The table now holds 2 different emails for customer 17, and no column says which is current. A query can count the damage. Redundancy: one fact in many cells A fact is one true statement about the business,

  2. First Normal Form (1NF)

    What a multi-value cell costs Repeating groups: the same flaw in columns The repair: one row per value The result is 3: 2 units from order 1001 and 1 from order 1015. The holder on order 1020 is product 504 and stays out of the total. How small is a single value? 1NF made every value reachable with ordinary comparisons. It also multiplied the repeated facts: order 1001 now has 2 rows, so anything true of the whole order is written on both. The next 2 forms remove that repetition.

  3. Second Normal Form (2NF)

    Functional dependency: what determines what Now ask of each non-key column: which part of the key do I need to know this? The 2NF rule Which price belongs where?

  4. Third Normal Form (3NF)

    Transitive dependency: a chain through a non-key column The 3NF rule The repair is the same move as in 2NF. Take the dependent column out and put it in a table keyed by the column that determines it. The rule reaches further than lookups such as an email. Any non-key column that other non-key columns determine fails it. What 3NF costs The shop went from 1 table to 4. Writes became cheap and safe: every fact has 1 home, so an update touches 1 row. Reads became longer. Units sold per customer emai

  5. Identifying Normal Form

    Normal forms are cumulative. A table is in 2NF only if it is also in 1NF, and in 3NF only if it is also in 2NF. Diagnosing a table means running the tests in order and stopping at the first failure. The table's normal form is the last test it passed. The 4-step diagnosis A worked diagnosis Rules come from the business, evidence from the data The diagnosis leaned on rules the gym staff stated. Column names suggest dependencies and cannot confirm them. Data can test a suspected rule, though: if A