Normalization: 1NF, 2NF, 3NF, BCNF and When to Denormalize
What normalization is and why it matters: update, insert and delete anomalies, functional dependencies and how to test them with SQL, first, second and third normal form and BCNF, decomposing a flat table without losing data, and when to denormalize deliberately.
kvi5hnuCode Sprout team member11 min readOn this page
Data often starts life as one wide table: a spreadsheet export, an imported CSV, a quick prototype. Every row holds everything about an order line, from the customer's name and city to the product's name and price. It's easy to read, and it causes trouble as soon as the data changes.
Normalization is the process of splitting such tables so that each fact is stored in exactly one place. It's guided by a series of normal forms, each removing one kind of redundancy. Article 50 designed tables from entities; this article checks a design and repairs a flat one. The runnable examples start from this table:
CREATE TABLE order_sheet (
order_id INTEGER, placed_on DATE, customer_name TEXT, customer_city TEXT,
product_id INTEGER, product_name TEXT, unit_price DECIMAL(8, 2), qty INTEGER,
PRIMARY KEY (order_id, product_id)
);
-- 5 rows: orders 101 and 103 by Asha Rao of Pune, order 102 by Ben Okafor of Leeds
The problem: anomalies
Redundant data causes three kinds of anomaly:
-- Orders as they might arrive from a spreadsheet: one wide table, one row per order line
CREATE TABLE order_sheet (
order_id INTEGER,
placed_on DATE,
customer_name TEXT,
customer_city TEXT,
product_id INTEGER,
product_name TEXT,
unit_price DECIMAL(8, 2),
qty INTEGER,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_sheet VALUES
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 1, 'Ridge 2 tent', 249.99, 1),
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 7, 'Merino socks', 16.00, 3),
(102, DATE '2026-03-05', 'Ben Okafor', 'Leeds', 3, 'Glow head torch', 34.50, 2),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 5, 'Trail 30 backpack', 89.95, 1),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 3, 'Glow head torch', 34.50, 1);
-- An update anomaly: Asha moves, but only one order's rows are changed
UPDATE order_sheet SET customer_city = 'Mumbai' WHERE order_id = 103;
-- Now the data contradicts itself: which city is right?
SELECT customer_name, string_agg(DISTINCT customer_city, ', ') AS cities
FROM order_sheet
GROUP BY customer_name
HAVING COUNT(DISTINCT customer_city) > 1;
-- A deletion anomaly: deleting order 102 also deletes the only record of Ben Okafor
DELETE FROM order_sheet WHERE order_id = 102;
SELECT COUNT(*) AS rows_mentioning_ben FROM order_sheet WHERE customer_name = 'Ben Okafor';
customer_name | cities
---------------+--------------
Asha Rao | Mumbai, Pune
(1 row)
rows_mentioning_ben
---------------------
0
(1 row)
- Update anomaly. Asha's city is stored on every one of Asha's order lines. Updating only some of them, here the rows of order 103, leaves the data contradicting itself: Asha now lives in both Mumbai and Pune. Every copy must be changed together, and sooner or later one is missed.
- Deletion anomaly. Ben exists only as part of order 102. Deleting the order deletes everything known about Ben.
- Insertion anomaly. A new customer who hasn't ordered yet can't be added at all:
order_idandproduct_idform the primary key, so they can't be NULL. The same goes for a new product that hasn't been sold.
The root cause is the same in all three: the table mixes facts about different things, customers, products, orders and order lines, in one row.
Functional dependencies
The normal forms are defined in terms of functional dependencies. Column B is functionally dependent on column A, written A → B, when each value of A always comes with the same value of B. In the sheet:
product_id → product_name: product 3 is always the Glow head torch.order_id → placed_on, customer_name: an order has one date and one customer.customer_name → customer_city: a customer has one city (until the update anomaly broke it).(order_id, product_id) → qty, unit_price: the quantity and price charged belong to the line.
Dependencies come from the meaning of the data, the business rules, not from the rows that happen to exist. But a query can test whether the data is consistent with a dependency: if any value of A has more than one distinct value of B, then A → B doesn't hold.
-- Orders as they might arrive from a spreadsheet: one wide table, one row per order line
CREATE TABLE order_sheet (
order_id INTEGER,
placed_on DATE,
customer_name TEXT,
customer_city TEXT,
product_id INTEGER,
product_name TEXT,
unit_price DECIMAL(8, 2),
qty INTEGER,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_sheet VALUES
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 1, 'Ridge 2 tent', 249.99, 1),
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 7, 'Merino socks', 16.00, 3),
(102, DATE '2026-03-05', 'Ben Okafor', 'Leeds', 3, 'Glow head torch', 34.50, 2),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 5, 'Trail 30 backpack', 89.95, 1),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 3, 'Glow head torch', 34.50, 1);
-- Testing a functional dependency: does product_id determine product_name and unit_price?
-- Any product_id with more than one distinct value breaks the dependency
SELECT product_id,
COUNT(DISTINCT product_name) AS names,
COUNT(DISTINCT unit_price) AS prices
FROM order_sheet
GROUP BY product_id
HAVING COUNT(DISTINCT product_name) > 1 OR COUNT(DISTINCT unit_price) > 1;
-- Does order_id determine placed_on and the customer? (It should: they're facts about the order)
SELECT order_id
FROM order_sheet
GROUP BY order_id
HAVING COUNT(DISTINCT placed_on) > 1 OR COUNT(DISTINCT customer_name) > 1;
-- Which columns depend on only part of the key (order_id, product_id)?
SELECT 'product_name depends on product_id alone' AS finding
WHERE NOT EXISTS (SELECT 1 FROM order_sheet GROUP BY product_id HAVING COUNT(DISTINCT product_name) > 1)
UNION ALL
SELECT 'placed_on depends on order_id alone'
WHERE NOT EXISTS (SELECT 1 FROM order_sheet GROUP BY order_id HAVING COUNT(DISTINCT placed_on) > 1);
product_id | names | prices
------------+-------+--------
(0 rows)
order_id
----------
(0 rows)
finding
------------------------------------------
product_name depends on product_id alone
placed_on depends on order_id alone
(2 rows)
The pattern is GROUP BY a HAVING COUNT(DISTINCT b) > 1: an empty result means the data agrees with the dependency. Run it on imported data before designing tables from it, and on existing tables to find inconsistencies like Asha's two cities. The third query confirms that product_name and placed_on depend on part of the key, which is exactly what second normal form is about.
First normal form
A table is in first normal form (1NF) when every column holds a single, atomic value, with no lists, no repeating groups, and a key that identifies each row.
-- First normal form: a list in a column is a repeating group
CREATE TABLE product_tags_flat (product_id INTEGER PRIMARY KEY, tags TEXT);
INSERT INTO product_tags_flat VALUES (1, 'camping, waterproof'), (3, 'lighting, camping'), (7, 'clothing');
-- Which products are tagged 'camping'? Easy to get wrong with LIKE; correct with one row per tag
CREATE TABLE product_tags AS
SELECT product_id, trim(t) AS tag
FROM product_tags_flat, string_to_table(tags, ',') AS t;
ALTER TABLE product_tags ADD PRIMARY KEY (product_id, tag);
SELECT product_id, tag FROM product_tags ORDER BY product_id, tag;
SELECT product_id FROM product_tags WHERE tag = 'camping' ORDER BY product_id;
product_id | tag
------------+------------
1 | camping
1 | waterproof
3 | camping
3 | lighting
7 | clothing
(5 rows)
product_id
------------
1
3
(2 rows)
tags = 'camping, waterproof' breaks 1NF. Finding the camping products with LIKE '%camping%' would also match a tag such as 'campfire-safe-camping-mug', the tags can't be validated or indexed individually, and removing one tag means rewriting the string. Splitting the list into a product_tags table, one row per product and tag, makes "products tagged camping" an exact match, and the composite primary key stops a tag being added twice. Columns such as phone1, phone2, phone3 are the same problem in another form: a repeating group spread across columns (article 45).
"Atomic" depends on use. A date is one value, although it has a year, a month and a day. An address in a single column is fine if it's only ever printed, but not if queries filter by postcode. Arrays and JSON columns (article 43) are a deliberate exception when the list is always read and written as a whole.
Second normal form
A table is in second normal form (2NF) when it's in 1NF and every non-key column depends on the whole primary key, not just part of it. 2NF only matters for tables with a composite key.
The sheet's key is (order_id, product_id), but:
product_namedepends onproduct_idalone, so it's repeated for every order of the product.placed_on,customer_nameandcustomer_citydepend onorder_idalone, so they're repeated for every line of the order.
The fix is to move each group into a table keyed by the part it depends on: product columns into products, order columns into orders. Only qty and unit_price depend on the whole key, and they stay in order_items.
Third normal form
A table is in third normal form (3NF) when it's in 2NF and no non-key column depends on another non-key column. Such a transitive dependency means the column is really a fact about something else.
After the 2NF split, orders would still contain customer_name and customer_city: order_id → customer_name → customer_city. The city is a fact about the customer, not the order. So the customer columns move to a customers table, and orders keeps only a customer_id foreign key.
A memorable summary of 1NF to 3NF: every non-key column must depend on the key, the whole key, and nothing but the key.

Decomposing without losing data
-- Orders as they might arrive from a spreadsheet: one wide table, one row per order line
CREATE TABLE order_sheet (
order_id INTEGER,
placed_on DATE,
customer_name TEXT,
customer_city TEXT,
product_id INTEGER,
product_name TEXT,
unit_price DECIMAL(8, 2),
qty INTEGER,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_sheet VALUES
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 1, 'Ridge 2 tent', 249.99, 1),
(101, DATE '2026-03-02', 'Asha Rao', 'Pune', 7, 'Merino socks', 16.00, 3),
(102, DATE '2026-03-05', 'Ben Okafor', 'Leeds', 3, 'Glow head torch', 34.50, 2),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 5, 'Trail 30 backpack', 89.95, 1),
(103, DATE '2026-03-09', 'Asha Rao', 'Pune', 3, 'Glow head torch', 34.50, 1);
-- Decomposition: split the sheet into one table per entity
CREATE TABLE n_customers (
customer_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
city TEXT
);
INSERT INTO n_customers (name, city)
SELECT DISTINCT customer_name, customer_city FROM order_sheet ORDER BY customer_name;
CREATE TABLE n_products AS
SELECT DISTINCT product_id, product_name AS name FROM order_sheet;
ALTER TABLE n_products ADD PRIMARY KEY (product_id);
CREATE TABLE n_orders AS
SELECT DISTINCT s.order_id, s.placed_on, c.customer_id
FROM order_sheet s JOIN n_customers c ON c.name = s.customer_name;
ALTER TABLE n_orders ADD PRIMARY KEY (order_id);
CREATE TABLE n_order_items AS
SELECT order_id, product_id, qty, unit_price FROM order_sheet;
ALTER TABLE n_order_items ADD PRIMARY KEY (order_id, product_id);
SELECT (SELECT COUNT(*) FROM n_customers) AS customers,
(SELECT COUNT(*) FROM n_products) AS products,
(SELECT COUNT(*) FROM n_orders) AS orders,
(SELECT COUNT(*) FROM n_order_items) AS order_items;
-- Lossless? Joining the parts back must give exactly the original rows
(SELECT o.order_id, o.placed_on, c.name, c.city, p.product_id, p.name, i.unit_price, i.qty
FROM n_order_items i
JOIN n_orders o ON o.order_id = i.order_id
JOIN n_customers c ON c.customer_id = o.customer_id
JOIN n_products p ON p.product_id = i.product_id)
EXCEPT
(SELECT * FROM order_sheet);
-- Now Asha's city is stored once: changing it is one row, and it can't disagree with itself
UPDATE n_customers SET city = 'Mumbai' WHERE name = 'Asha Rao';
SELECT name, city FROM n_customers ORDER BY customer_id;
customers | products | orders | order_items
-----------+----------+--------+-------------
2 | 4 | 3 | 5
(1 row)
order_id | placed_on | name | city | product_id | name | unit_price | qty
----------+-----------+------+------+------------+------+------------+-----
(0 rows)
name | city
------------+--------
Asha Rao | Mumbai
Ben Okafor | Leeds
(2 rows)
The decomposition creates one table per entity from the sheet's distinct values (article 31 covers CREATE TABLE ... AS and INSERT ... SELECT). Customers get a surrogate key, because names aren't reliable identifiers, and orders looks up each customer's new ID by name. The sheet has no customer ID, so here the name is the only way to tell customers apart, and the UNIQUE constraint makes that assumption explicit. Real data would need a better identifier, such as an email address.
A decomposition must be lossless: joining the tables back must give exactly the original rows, no more and no fewer. The EXCEPT query (article 15) checks this, and returns no rows. A decomposition is lossless when each split shares a column that's a key of one of the parts, as customer_id, order_id and product_id are here. Splitting on a non-key column, such as city, would make the rejoin produce spurious rows.
After the split, Asha's city is stored once, and the update anomaly is gone: moving to Mumbai changes one row. Customers can exist without orders, products without sales, and deleting an order no longer deletes a customer.
(This example ran the decomposition before Asha's partial move, so the data was consistent. With contradictory data, SELECT DISTINCT customer_name, customer_city would create two Asha rows, and the UNIQUE constraint on name would reject the second: decomposition forces you to resolve inconsistencies, which is part of its value.)
Boyce-Codd normal form and beyond
Boyce-Codd normal form (BCNF) tightens 3NF: for every non-trivial dependency A → B, A must be a candidate key. Tables in 3NF but not BCNF are rare, and they involve overlapping candidate keys. The classic example is (student, course, instructor), where each instructor teaches only one course: instructor → course, but instructor isn't a key. Recording that an instructor teaches a course is impossible without enrolling a student. Splitting into (instructor, course) and (student, instructor) fixes it.
Fourth normal form deals with multi-valued dependencies: two independent lists stored in one table, such as an employee's skills and their languages in rows of (employee, skill, language), which forces every combination to be stored. The fix is the same, a table per independent fact. In practice, a design built from entities and junction tables (article 50) is usually in BCNF or better already.
When to denormalize
A normalized design is the right starting point for data that's written and changed, which is what most operational databases do. Denormalization, storing redundant data on purpose, trades update cost and consistency for read speed or simplicity. Valid reasons include:
- Expensive, frequently read derived values, such as an order's total or a product's average rating, read on every page view and computed from many rows.
- Reporting and analytics: data warehouses use star schemas, with wide, deliberately redundant dimension tables, because the data is loaded in batches and read in large scans, not updated row by row.
- Historical snapshots: an invoice must show the address it was sent to, even after the customer moves. Copying the address into the invoice isn't really redundancy; it's a different fact.
CREATE TABLE products (
product_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
category VARCHAR(20) NOT NULL,
brand VARCHAR(20),
price DECIMAL(8, 2) NOT NULL,
stock INTEGER NOT NULL,
weight_g INTEGER
);
INSERT INTO products VALUES
(1, 'Ridge 2 tent', 'tents', 'Alpina', 249.99, 12, 2100),
(2, 'Summit 4 tent', 'tents', 'Alpina', 489.00, 3, 4300),
(3, 'Glow head torch', 'lighting', 'Lumen', 34.50, 40, 90),
(4, 'Basecamp lantern', 'lighting', NULL, 27.00, 15, NULL),
(5, 'Trail 30 backpack', 'packs', 'Kestrel', 89.95, 22, 1150),
(6, 'Day 18 backpack', 'packs', 'Kestrel', 54.00, 0, 640),
(7, 'Merino socks', 'clothing', 'Woolly', 16.00, 75, 80);
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
name VARCHAR(40) NOT NULL,
city VARCHAR(30),
referred_by INTEGER REFERENCES customers (customer_id)
);
INSERT INTO customers VALUES
(1, 'Asha Rao', 'Pune', NULL),
(2, 'Ben Okafor', 'Leeds', 1),
(3, 'Chen Wei', 'Pune', 1),
(4, 'Dana Cruz', 'York', 2),
(5, 'Eli Novak', 'Leeds', NULL),
(6, 'Farah Haddad', NULL, 3);
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER REFERENCES customers (customer_id), -- NULL = guest checkout
placed_on DATE NOT NULL,
status VARCHAR(10) NOT NULL
);
INSERT INTO orders VALUES
(101, 1, DATE '2026-03-02', 'shipped'),
(102, 2, DATE '2026-03-05', 'shipped'),
(103, 1, DATE '2026-03-09', 'delivered'),
(104, 3, DATE '2026-03-15', 'pending'),
(105, 4, DATE '2026-03-20', 'cancelled'),
(106, NULL, DATE '2026-03-22', 'shipped');
CREATE TABLE order_items (
order_id INTEGER REFERENCES orders (order_id),
product_id INTEGER REFERENCES products (product_id),
qty INTEGER NOT NULL,
unit_price DECIMAL(8, 2) NOT NULL,
PRIMARY KEY (order_id, product_id)
);
INSERT INTO order_items VALUES
(101, 1, 1, 249.99), (101, 7, 3, 16.00),
(102, 3, 2, 34.50),
(103, 5, 1, 89.95), (103, 3, 1, 34.50), (103, 7, 2, 15.00),
(104, 2, 1, 489.00),
(105, 6, 1, 54.00),
(106, 7, 1, 16.00);
-- Deliberate denormalisation: a stored order total, and a check that it hasn't drifted
ALTER TABLE orders ADD COLUMN total DECIMAL(10, 2);
UPDATE orders o
SET total = (SELECT SUM(qty * unit_price) FROM order_items i WHERE i.order_id = o.order_id);
-- Later, a line changes but the total isn't updated
UPDATE order_items SET qty = 3 WHERE order_id = 102 AND product_id = 3;
SELECT o.order_id, o.total AS stored_total, SUM(i.qty * i.unit_price) AS actual_total
FROM orders o
JOIN order_items i ON i.order_id = o.order_id
GROUP BY o.order_id, o.total
HAVING o.total IS DISTINCT FROM SUM(i.qty * i.unit_price)
ORDER BY o.order_id;
order_id | stored_total | actual_total
----------+--------------+--------------
102 | 69.00 | 103.50
(1 row)
The stored total was correct when computed, but a later change to order 102's quantity didn't update it. That's the price of redundancy: something must keep the copies in step. The options, from most to least reliable:
- Don't store it: compute it in a view (article 56) and add an index if it's slow.
- A generated column (article 52), when the value derives from the same row.
- A materialized view (article 56), refreshed on a schedule, when slightly stale data is acceptable.
- A trigger (article 65) that updates the copy in the same transaction.
- Application code that remembers to update both, plus a drift check like the query above, run regularly.
Measure before denormalizing: a well-indexed join is usually fast enough.
What's current
- Normal forms are decades old and unchanged. What has changed is that JSON columns (article 43) give a controlled way to store non-1NF data, and that analytics now often runs on separate columnar systems, so the operational database can stay normalized.
- PostgreSQL 18 made virtual generated columns the default kind of generated column, computing derived values when read rather than storing them.
Common questions
What does normalization achieve? Each fact is stored once, so data can't contradict itself, and inserts, updates and deletes don't have side effects on unrelated facts.
How far should I normalize? To 3NF or BCNF for operational data. Denormalize specific, measured hot spots afterwards, with a way to keep copies consistent.
What's the difference between 2NF and 3NF? 2NF removes columns that depend on part of a composite key. 3NF removes columns that depend on another non-key column.
Is a comma-separated list in a column always wrong? For data you search, join or validate, yes: use a child table. Arrays or JSON are acceptable when the list is only ever read and written as a whole.
Doesn't normalization make queries slower because of joins? Joins on indexed keys are fast. Normalization also makes tables smaller and updates cheaper. Denormalize only where measurement shows a need.
Summary
- Redundant data causes update, insertion and deletion anomalies.
- A functional dependency A → B means each A has one B. Test the data with
GROUP BY a HAVING COUNT(DISTINCT b) > 1. - 1NF: atomic values, no lists or repeating groups.
- 2NF: no column depends on only part of a composite key.
- 3NF: no column depends on another non-key column. BCNF: every determinant is a candidate key.
- Decompose into one table per entity, and check that the decomposition is lossless.
- Denormalize deliberately, for measured read performance or reporting, with a mechanism that keeps copies consistent.
Practice questions
A table employees(emp_id PK, name, dept_id, dept_name) has which normal form problem, and how do you fix it?
Answer
A transitive dependency, emp_id → dept_id → dept_name, so it breaks 3NF: a department's name is repeated for every employee and can become inconsistent. Move dept_name to departments(dept_id PK, dept_name) and keep dept_id in employees as a foreign key.
Write a query that checks whether customer_name → customer_city holds in order_sheet.
Answer
SELECT customer_name
FROM order_sheet
GROUP BY customer_name
HAVING COUNT(DISTINCT customer_city) > 1;
An empty result means the data is consistent with the dependency. After the partial update, it returns Asha Rao.
A table enrolments(student_id, course_id, course_title, grade) has the key (student_id, course_id). Which normal form does it break?
Answer
2NF. course_title depends on course_id alone, part of the key. Move it to a courses table.
Give one good reason to store an order's total even though it can be computed from its lines, and what must accompany it.
Answer
It's read far more often than the lines change, for example on every listing of a customer's orders, and computing it each time is measurably slow. It must come with a mechanism that keeps it correct, such as a trigger, plus a check like the drift query that detects disagreements.
Previous: Database Design: Entities, Relationships and ER Diagrams
Next: CREATE TABLE and Constraints: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and DEFAULT

More in SQL Course
Quiz: SQL Dialect Differences (PostgreSQL, MySQL, SQL Server, Oracle, SQLite)
Twenty-four questions on how the major SQL databases differ: limiting rows, concatenation, empty strings, identifier case, upserts, identity columns, transactional DDL, error handling, isolation defaults, booleans, set operations, RETURNING, dates and typing.
Quiz: SQL Delicate Details
Twenty-five questions on SQL's subtle corners: NULLs in aggregates, IN and CHECK, sort order of NULLs, rounding, CHAR padding, window frame defaults, identity gaps, LIKE escapes, empty groups, set operations and multi-column updates.
Quiz: SQL Interview Questions
Thirty SQL questions of the kind asked in developer and analyst interviews: WHERE vs HAVING, DELETE vs TRUNCATE, keys, joins, duplicates, Nth-highest values, window functions, ACID, isolation, locking, indexes, views, procedures and performance.
Quiz: SQL Course Final Exam (All 15 Parts)
The final exam for the SQL course: thirty questions across all fifteen parts, from query processing, NULLs, joins and aggregation through windows, data changes, types, design, indexes, security, transactions, procedural SQL and tuning.
Discussion
Sign in to ask a question or share what you learned.