Normalization
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_id | product_name | list_price | customer_id | customer_email |
|---|---|---|---|---|
| 1001 | Burr Grinder | 89.00 | 17 | maya@oldmail.com |
| 1001 | Paper Filters | 6.25 | 17 | maya@oldmail.com |
| 1014 | Pour-Over Kettle | 42.50 | 17 | maya@oldmail.com |
| 1015 | Paper Filters | 6.25 | 22 | dev@patel.io |
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 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.
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
- 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.
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
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_id | customer_id | items |
|---|---|---|
| 1001 | 17 | Burr Grinder x1, Paper Filters x2 |
| 1014 | 17 | Pour-Over Kettle x1 |
| 1015 | 22 | Paper Filters x1 |
| 1020 | 31 | Paper 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.
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_id | item_1 | qty_1 | item_2 | qty_2 |
|---|---|---|---|---|
| 1001 | Burr Grinder | 1 | Paper Filters | 2 |
| 1014 | Pour-Over Kettle | 1 | NULL | NULL |
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.
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_id | product_id | product_name | quantity |
|---|---|---|---|
| 1001 | 501 | Burr Grinder | 1 |
| 1001 | 502 | Paper Filters | 2 |
| 1014 | 503 | Pour-Over Kettle | 1 |
| 1015 | 502 | Paper Filters | 1 |
| 1020 | 504 | Paper Filters Holder | 1 |
This is orders_flat, shown without its customer columns. Products are now values the database can compare, join and add up.
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.
Which table fails 1NF, for the reason given?
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_id | product_id | quantity | product_name | list_price | order_date | customer_id |
|---|---|---|---|---|---|---|
| 1001 | 501 | 1 | Burr Grinder | 89.00 | 2026-03-02 | 17 |
| 1001 | 502 | 2 | Paper Filters | 6.25 | 2026-03-02 | 17 |
| 1014 | 503 | 1 | Pour-Over Kettle | 42.50 | 2026-03-09 | 17 |
| 1015 | 502 | 1 | Paper Filters | 6.25 | 2026-03-10 | 22 |
| 1020 | 504 | 1 | Paper Filters Holder | 14.00 | 2026-03-12 | 31 |
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.
| Column | Determined by | Needs the whole key? |
|---|---|---|
| quantity | (order_id, product_id) | Yes |
| product_name | product_id | No |
| list_price | product_id | No |
| order_date | order_id | No |
| customer_id | order_id | No |
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.
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.
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.
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.
Here is orders after the 2NF split, with the email Ruth's update left behind.
| order_id | order_date | customer_id | customer_email |
|---|---|---|---|
| 1001 | 2026-03-02 | 17 | maya@oldmail.com |
| 1014 | 2026-03-09 | 17 | maya@newmail.com |
| 1015 | 2026-03-10 | 22 | dev@patel.io |
| 1020 | 2026-03-12 | 31 | sam@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.
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.
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?
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
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.
The 4-step diagnosis
- 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_id | session_id | booked_at | member_name | class_name | trainer_id | trainer_name |
|---|---|---|---|---|---|---|
| 8 | 300 | 2026-05-04 18:02 | Ana Ruiz | Spin | 4 | Kofi Mensah |
| 9 | 300 | 2026-05-04 19:15 | Tom Becker | Spin | 4 | Kofi Mensah |
| 8 | 311 | 2026-05-05 07:40 | Ana Ruiz | Yoga | 6 | Priya 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
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.
A community library imports its paper loan sheet as one table. Each new requirement exposes a flaw. Pick the change that fixes the cause.
| loan_idBIGINTPK | member_idBIGINT | member_phoneVARCHAR | book_titlesVARCHAR | due_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?
> 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.
(delivery_id, recipe_id).recipe_id alone, a partial dependency. Moving it to a recipes table removes the update anomaly behind the 2 calorie counts.subscriber_id, a non-key column of deliveries. That transitive dependency kept old addresses alive, and a subscribers table gives each address 1 home.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
- 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,
- 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.
- 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?
- 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
- 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