skip to content

normal forms, 1NF to BCNF

one fact, one place. update, insert and delete anomalies, and the decomposition that cures them.

address
everything.design.normal_forms
part
part 7, schema design
chapter
chapter 6 of 13
reading time
13 min

one fact, one place. when a table stores the same fact in many rows (a customer's address on every order line), the copies can disagree. that's the update anomaly, and it comes with two siblings: you can't store a fact until something unrelated exists (insert), and deleting one thing deletes another (delete).

the normal forms are a checklist for finding those copies. 3NF (or BCNF, which is nearly always the same table) is the everyday target. the cure is always the same move: split the table along a functional dependency.

the picture

you know the spreadsheet everyone starts with? one row per order line, and every row spells out the customer's name, email and address, because that's what the invoice needs. it reads well. it also stores Ada's address four times, and nothing in the table says those four have to match.

think of writing your friend's address on the back of every photo you've sent her (the order lines), instead of keeping it once in your address book (a customers table). the day she moves, you have to find every photo. miss one, and you now know two addresses for her, with no way to tell which is current.

schema =
orders_wide, one row per order line5 rows
the wide table: one row per order line, the address copied into each
order_idint4skutextproducttextcustomertextaddresstext
101MUG-02blue mugAda Lovelace
101TEA-01assam teaAda Lovelace
102TEA-01assam teaAda Lovelace
103TEA-02green teaGrace Okafor
104MUG-02blue mugAda Lovelace

every order line carries a copy of the address. edit one copy (or press × to delete an order line, or add a customer who hasn't ordered).

you edited itcopies that disagree
real output, postgres 18.6 (PGlite 0.5.12) · normalize
your edits stay in this page; the blocks below run them on postgres
the same five order lines, two ways. in one wide table, edit Ada's address on one row: the copies now disagree. press × on Grace's only row, or add Ming Li, who hasn't ordered. then switch to split in two and edit the address once: every line reads it from the one row.

the lab edits rows in your browser. the three anomalies are real postgres behaviour though, so here they are on the engine.

three anomalies, for real

the wide table, keyed by (order_id, sku), the way the lab shows it:

orders_wide.sqlempty db · session wide
CREATE TABLE orders_wide (
  order_id   int  NOT NULL,
  sku        text NOT NULL,
  qty        int  NOT NULL,
  product    text NOT NULL,
  list_price numeric(8,2) NOT NULL,
  ordered_on date NOT NULL,
  email      text NOT NULL,
  customer   text NOT NULL,
  address    text NOT NULL,
  PRIMARY KEY (order_id, sku)
);
INSERT INTO orders_wide VALUES
  (101, 'TEA-01', 2, 'assam tea', 6.50, '2026-03-02', 'ada@example.com',   'Ada Lovelace', '12 Byron St, London'),
  (101, 'MUG-02', 1, 'blue mug',  9.00, '2026-03-02', 'ada@example.com',   'Ada Lovelace', '12 Byron St, London'),
  (102, 'TEA-01', 1, 'assam tea', 6.50, '2026-03-03', 'ada@example.com',   'Ada Lovelace', '12 Byron St, London'),
  (103, 'TEA-02', 3, 'green tea', 5.00, '2026-03-04', 'grace@example.com', 'Grace Okafor', '4 Elm Rd, Leeds'),
  (104, 'MUG-02', 2, 'blue mug',  9.00, '2026-03-05', 'ada@example.com',   'Ada Lovelace', '12 Byron St, London');
output, from postgres 18.6
#1 · CREATE TABLE
#2 · INSERT 0 5
predict the output
sql
-- Ada moved. the support agent fixes her latest order.
UPDATE orders_wide SET address = '3 Kew Gardens, London'
WHERE order_id = 104;
 
SELECT DISTINCT address FROM orders_wide
WHERE email = 'ada@example.com';

the update anomaly:

sqlempty db · session wide
continues session wide (1 earlier block run first)
UPDATE orders_wide SET address = '3 Kew Gardens, London' WHERE order_id = 104;
 
SELECT DISTINCT address FROM orders_wide WHERE email = 'ada@example.com' ORDER BY address;
output, from postgres 18.6
#1 · UPDATE 1
#2 · SELECT 2
addresstext
12 Byron St, London
3 Kew Gardens, London
(2 rows)

UPDATE 1, and two answers. the fix "just update every row with her email" works until the day someone forgets, or two people edit at once, or the email itself is the thing that changed.

the insert anomaly: Ming Li signs up but hasn't ordered. every row is an order line, so to store her address you need an order id and a sku, and a key column can't be NULL:

sqlempty db · session wide
continues session wide (2 earlier blocks run first)
INSERT INTO orders_wide (email, customer, address)
VALUES ('ming@example.com', 'Ming Li', '9 Canal St, Manchester');
output, from postgres 18.6
ERROR 23502: null value in column "order_id" of relation "orders_wide" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null, null, null, ming@example.com, Ming Li, 9 Canal St, Manchester).

the delete anomaly: Grace cancels her only order, and the shop forgets she exists. green tea goes too, since order 103 was the only row that knew its name and price:

sqlempty db · session wide
continues session wide (3 earlier blocks run first)
DELETE FROM orders_wide WHERE order_id = 103;
 
SELECT count(*) FILTER (WHERE email = 'grace@example.com') AS grace_rows,
       count(*) FILTER (WHERE sku = 'TEA-02') AS green_tea_rows
FROM orders_wide;
output, from postgres 18.6
#1 · DELETE 1
#2 · SELECT 1
grace_rowsint8green_tea_rowsint8
00
(1 row)

three different symptoms, one disease: the table holds facts about several things (order lines, orders, products, customers), and each fact is stored once per row of the thing it isn't about.

the cure: split along the dependencies

a functional dependency X → Y says "rows that agree on X agree on Y". this table has four groups of them, and the key is (order_id, sku):

  • key: (order_id, sku)
  • ├── 1NF: one value per cellalready true here, see below
  • ├──
  • │ ├── sku → product, list_priceonly half the key
  • │ ├── order_id → ordered_on, emailthe other half
  • │ ├── products (sku, product, list_price)
  • │ ├── orders (order_id, ordered_on, email, customer, address)
  • │ └── order_lines (order_id, sku, qty)
  • └──
  • ├── email → customer, addressinside orders
  • ├── customers (id, email, name, address)
  • └── orders (order_id, ordered_on, customer_id)
the decomposition, one step per normal form. each split moves a dependency into a table where its left side is the key. dead marks the dependency that breaks the form at that step, live the tables each split produces.

1NF: one value per cell

first normal form asks that every cell hold one value, and that rows have a key. the classic violation is a list in a string:

sqlempty db
CREATE TABLE orders_csv (order_id int PRIMARY KEY, skus text);
INSERT INTO orders_csv VALUES (101, 'TEA-01,MUG-02'), (102, 'TEA-01');
 
SELECT order_id, sku
FROM orders_csv, string_to_table(skus, ',') AS sku
ORDER BY order_id, sku;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · INSERT 0 2
#3 · SELECT 3
order_idint4skutext
101MUG-02
101TEA-01
102TEA-01
(3 rows)

you can split it at read time, as above, but you can't put a foreign key on part of a string, can't index "orders containing MUG-02" with a plain b-tree, and can't stop 'TEA-01,,tea-01'. one row per item is 1NF. (schema anti-patterns has the full damage report.)

"one value" is fuzzier than it sounds. a date has a year inside it, an address has a city, and postgres happily stores arrays and jsonb. the working rule: if you'll query, constrain or join on the parts, they're separate values. if the whole thing is only ever read and written as one, it's one.

2NF: the whole key

second normal form only bites when the key has several columns. it says no non-key column may depend on part of the key. here product and list_price depend on sku alone, and ordered_on, email, customer and address on order_id alone. postgres can check the first claim: if any sku had two product names, this would return it.

sqlempty db · session wide
continues session wide (4 earlier blocks run first)
SELECT sku, count(DISTINCT (product, list_price)) AS versions
FROM orders_wide
GROUP BY sku
HAVING count(DISTINCT (product, list_price)) > 1
ORDER BY sku;
output, from postgres 18.6
SELECT 0
skutextversionsint8
(0 rows)

no rows: sku → (product, list_price) holds in this data. so products get their own table, keyed by sku, and the line keeps only what depends on the whole (order_id, sku): qty.

3NF: nothing but the key

the orders table after 2NF still says (order_id → email) and (email → customer, address). the address depends on the key only through email, a transitive dependency. third normal form says a non-key column must depend on the key directly, so customers move out. the old mnemonic: every non-key column depends on the key, the whole key, and nothing but the key.

here's the whole decomposition, filled from the wide table (a fresh copy, before the edits above):

normalized.sqlempty db · session split
continues session split (1 earlier block run first)
CREATE TABLE customers (
  id      int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  email   text NOT NULL UNIQUE,
  name    text NOT NULL,
  address text NOT NULL
);
CREATE TABLE products (sku text PRIMARY KEY, name text NOT NULL, list_price numeric(8,2) NOT NULL);
CREATE TABLE orders (
  id          int PRIMARY KEY,
  ordered_on  date NOT NULL,
  customer_id int NOT NULL REFERENCES customers
);
CREATE TABLE order_lines (
  order_id int  NOT NULL REFERENCES orders,
  sku      text NOT NULL REFERENCES products,
  qty      int  NOT NULL,
  PRIMARY KEY (order_id, sku)
);
 
INSERT INTO customers (email, name, address)
SELECT DISTINCT email, customer, address FROM orders_wide ORDER BY email;
INSERT INTO products SELECT DISTINCT sku, product, list_price FROM orders_wide ORDER BY sku;
INSERT INTO orders
SELECT DISTINCT w.order_id, w.ordered_on, c.id
FROM orders_wide AS w JOIN customers AS c USING (email) ORDER BY 1;
INSERT INTO order_lines SELECT order_id, sku, qty FROM orders_wide ORDER BY 1, 2;
 
SELECT (SELECT count(*) FROM customers) AS customers, (SELECT count(*) FROM products) AS products,
       (SELECT count(*) FROM orders) AS orders, (SELECT count(*) FROM order_lines) AS lines;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · CREATE TABLE
#3 · CREATE TABLE
#4 · CREATE TABLE
#5 · INSERT 0 2
#6 · INSERT 0 3
#7 · INSERT 0 4
#8 · INSERT 0 5
#9 · SELECT 1
customersint8productsint8ordersint8linesint8
2345
(1 row)
customersidpkemailuniquenameaddressordersidpkordered_oncustomer_idfkorder_linesorder_idpk fkskupk fkqtyproductsskupknamelist_price
foreign key → the key it points at
drawn by hand · from the CREATE TABLEs below
the result: four tables, each about one thing. every line is a foreign key ending at the key it points to; the crow's foot is the many side. a customer can have zero orders now, which is the insert anomaly gone.

a split is only safe if it's lossless: joining the pieces back gives exactly the original rows, no more and no fewer. it is, because every split went along a dependency whose left side became a key. ask postgres both directions of the difference:

sqlempty db · session split
continues session split (2 earlier blocks run first)
WITH rejoined AS (
  SELECT l.order_id, l.sku, l.qty, p.name AS product, p.list_price, o.ordered_on, c.email, c.name AS customer, c.address
  FROM order_lines AS l
  JOIN orders AS o ON o.id = l.order_id
  JOIN products AS p USING (sku)
  JOIN customers AS c ON c.id = o.customer_id
)
SELECT (SELECT count(*) FROM (TABLE rejoined EXCEPT TABLE orders_wide) AS x) AS extra,
       (SELECT count(*) FROM (TABLE orders_wide EXCEPT TABLE rejoined) AS x) AS missing;
output, from postgres 18.6
SELECT 1
extraint8missingint8
00
(1 row)

zero and zero. now the three anomalies again, on the split tables. one UPDATE, one row, one address; Ming Li without an order; order 103 gone while Grace and green tea stay:

sqlempty db · session split
continues session split (3 earlier blocks run first)
UPDATE customers SET address = '3 Kew Gardens, London' WHERE email = 'ada@example.com';
INSERT INTO customers (email, name, address) VALUES ('ming@example.com', 'Ming Li', '9 Canal St, Manchester');
DELETE FROM order_lines WHERE order_id = 103;
DELETE FROM orders WHERE id = 103;
 
SELECT c.name, c.address, count(o.id) AS orders
FROM customers AS c LEFT JOIN orders AS o ON o.customer_id = c.id
GROUP BY c.id
ORDER BY c.id;
output, from postgres 18.6
#1 · UPDATE 1
#2 · INSERT 0 1
#3 · DELETE 1
#4 · DELETE 1
#5 · SELECT 3
nametextaddresstextordersint8
Ada Lovelace3 Kew Gardens, London3
Grace Okafor4 Elm Rd, Leeds0
Ming Li9 Canal St, Manchester0
(3 rows)
one level deeperthe price on the order line is not a copy

the shop dataset keeps unit_price on order_items even though products has a price, and that's correct. the product's price is "what it costs today". the line's price is "what this customer paid on that day". two different facts, so storing both is not redundancy: when the product's price changes, old orders must not. a value that looks repeated but means something different at a different time is history, and history, audit and soft delete is about keeping it on purpose.

BCNF: when a non-key decides part of the key

3NF has a loophole. it allows X → Y when Y is part of some candidate key. Boyce-Codd normal form closes it: for every non-trivial X → Y, X must be a superkey. tables that are 3NF but not BCNF are rare, and they all look alike: overlapping candidate keys. the textbook one is tutoring, where each tutor teaches one subject, and each student has one tutor per subject:

sqlempty db · session tutor
CREATE TABLE tutoring (
  student text NOT NULL,
  subject text NOT NULL,
  tutor   text NOT NULL,
  PRIMARY KEY (student, subject)
);
INSERT INTO tutoring VALUES
  ('Maya', 'math', 'Tomás'), ('Liam', 'math', 'Yuki'),
  ('Maya', 'physics', 'Amara'), ('Liam', 'physics', 'Amara');
 
SELECT tutor, subject, count(*) AS rows FROM tutoring GROUP BY tutor, subject ORDER BY tutor;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · INSERT 0 4
#3 · SELECT 3
tutortextsubjecttextrowsint8
Amaraphysics2
Tomásmath1
Yukimath1
(3 rows)

tutor → subject holds, but tutor isn't a key (Amara has two rows). so "Amara teaches physics" is stored twice, and one bad UPDATE can make her teach two subjects. it's 3NF (subject is part of the key), and not BCNF.

the BCNF split is tutors(tutor → subject) and lessons(student, tutor). and here's the catch: the rule "one tutor per student per subject" spanned both columns of the old key, and now the two columns live in different tables. no key can enforce it anymore:

sqlempty db · session tutor
continues session tutor (1 earlier block run first)
CREATE TABLE tutors (tutor text PRIMARY KEY, subject text NOT NULL);
CREATE TABLE lessons (student text, tutor text REFERENCES tutors, PRIMARY KEY (student, tutor));
INSERT INTO tutors SELECT DISTINCT tutor, subject FROM tutoring ORDER BY tutor;
INSERT INTO lessons SELECT student, tutor FROM tutoring ORDER BY 1, 2;
 
-- Maya gets a second math tutor. nothing objects.
INSERT INTO lessons VALUES ('Maya', 'Yuki');
 
SELECT l.student, t.subject, count(*) AS tutors
FROM lessons AS l JOIN tutors AS t USING (tutor)
GROUP BY l.student, t.subject
ORDER BY l.student, t.subject;
output, from postgres 18.6
#1 · CREATE TABLE
#2 · CREATE TABLE
#3 · INSERT 0 3
#4 · INSERT 0 4
#5 · INSERT 0 1
#6 · SELECT 4
studenttextsubjecttexttutorsint8
Liammath1
Liamphysics1
Mayamath2
Mayaphysics1
(4 rows)

that's the trade, and it's provable: some 3NF tables can't be decomposed into BCNF without losing a dependency. you pick between redundancy (stay at 3NF, the key keeps the rule) and a rule you enforce some other way, usually a trigger. most designers stay at 3NF here, and say so in a comment.

quick check
a table enrollments(student_id, course_code, term, grade, course_title) is keyed by (student_id, course_code, term). which form does course_title break first?

which forms matter

formthe rule, plainlyin practice
1NFone value per cell, rows have a keyalways. arrays and jsonb are fine when the value is read and written whole
2NFnon-key columns depend on the whole keyonly matters with composite keys. a surrogate id key is 2NF for free, which is also how people hide 2NF problems
3NF... and on nothing but the keythe everyday target. most anomalies you'll meet are 3NF violations
BCNFevery determinant is a keythe same tables as 3NF almost always. the exceptions have overlapping candidate keys
4NF, 5NFno independent multi-valued facts in one table, no join dependenciesrare. a table like (person, skill, language) storing two unrelated lists is the 4NF case

the forms past BCNF exist and are real, but you'll recognize their problems as "this table is about two unrelated lists" long before you name them. design to 3NF, check for the BCNF case when a table has two overlapping candidate keys, and then denormalize on purpose where a measured query needs it.

keylines

  • a fact stored in many rows can disagree with itself: update, insert and delete anomalies.
  • split along a functional dependency, its left side becomes the new table's key, and the join is lossless.
  • 2NF: the whole key. 3NF: nothing but the key. BCNF: every determinant is a key.
  • 3NF is the everyday target; BCNF can cost you a constraint.
  • a surrogate id doesn't normalize anything.