---
title: Normalization in DBMS: 1NF, 2NF, 3NF, BCNF Example
url: https://www.masaischool.com/resources/normalization-in-dbms-explained
description: Normalization in DBMS with one messy table taken to 3NF and BCNF in executed SQL, with the anomalies shown as real output and a rule for when to denormalise.
updated: 2026-12-01
publisher: Masai (https://www.masaischool.com)
---

# Normalization in DBMS: 1NF, 2NF, 3NF and BCNF with one worked example

> **Short answer**
>
> **Normalization** is the process of splitting a table so each fact is stored in exactly one place. 1NF removes repeating values, 2NF removes dependence on part of a key, 3NF removes dependence on non-key columns, and BCNF requires every determinant to be a key. The goal is to prevent update, insert and delete anomalies.

Most normalization pages define the four forms and stop. This one takes a single messy orders table and normalises it step by step, running every SQL statement in SQLite so the anomalies and the final check are real output, not diagrams. It is written for students preparing for DBMS interviews and for freshers designing their first schema.

Every code block was executed on SQLite 3.54.0 through Python's built-in sqlite3 module. Where SQLite behaves differently from MySQL or PostgreSQL, the text says so. For a list of questions to rehearse afterwards, see [SQL interview questions](https://www.masaischool.com/resources/sql-interview-questions); for how relational databases compare with other types, see [types of databases](https://www.masaischool.com/resources/types-of-databases-explained).

## The four normal forms in one table

Normalization means arranging columns into tables so that every fact is stored once and can only be changed in one place. It rests on one idea, the **functional dependency**: column A determines column B if each value of A always goes with exactly one value of B. A product_id determines a product_name; the reverse is not guaranteed.

| Form | Rule in plain words | Typical violation | Fix |
|---|---|---|---|
| 1NF | One value per cell, no repeating groups, rows identifiable by a key | A cell holding Pen x5, Notebook x3 | One row per order line |
| 2NF | 1NF, and every non-key column depends on the whole key | product_name in a table keyed by (order_id, product_id) | Move it to a products table |
| 3NF | 2NF, and non-key columns depend on the key and nothing but the key | city depends on pincode, which depends on the customer | Move pincode and city to their own table |
| BCNF | For every dependency X to Y, X must be a candidate key | teacher determines course but is not a key | Split so the determinant becomes a key |

Each form includes the one before it. In practice a well-designed schema reaches 3NF almost by accident if you ask one question about every column: what exactly identifies the thing this column describes?

## Start with the mess: 0NF to 1NF

Here is an order table as many beginners first draw it, with all items of an order packed into one text cell.import sqlite3 db = sqlite3.connect(":memory:") db.executescript(""" CREATE TABLE raw_orders (order_id INTEGER PRIMARY KEY, customer TEXT, items TEXT); INSERT INTO raw_orders VALUES (1, 'Asha', 'Notebook x3, Pen x5'), (2, 'Ravi', 'Notebook x2'), (3, 'Asha', 'Pen x8, Penknife x1'); """) # How many orders include a Pen? LIKE also matches Penknife. print(db.execute("SELECT order_id FROM raw_orders WHERE items LIKE '%Pen%'").fetchall()) # Total quantity of Pens cannot be computed with plain SQL here.[(1,), (3,)]

Two problems show up at once. LIKE '%Pen%' also matched order 3 because of Penknife, and nothing in plain SQL can add up the quantity of pens. A cell with a list breaks First Normal Form (1NF). The fix is one row per order line, with a composite primary key of (order_id, product_id). That table, sales_1nf, is the starting point for the rest of the page.

It is in 1NF, but it is still a bad design. The next section shows why.

## Anomalies in the 1NF table: update, delete, insert

Anomalies are the practical reason normalization exists. The script below builds sales_1nf and triggers all three.import sqlite3 db = sqlite3.connect(":memory:") db.executescript(""" CREATE TABLE sales_1nf ( order_id INTEGER NOT NULL, product_id INTEGER NOT NULL, product_name TEXT, unit_price INTEGER, qty INTEGER, customer_id INTEGER, customer_name TEXT, pincode TEXT, city TEXT, PRIMARY KEY (order_id, product_id)); INSERT INTO sales_1nf VALUES (1, 10, 'Notebook', 60, 3, 501, 'Asha', '560001', 'Bengaluru'), (1, 11, 'Pen', 10, 5, 501, 'Asha', '560001', 'Bengaluru'), (2, 10, 'Notebook', 60, 2, 502, 'Ravi', '411001', 'Pune'), (3, 11, 'Pen', 10, 8, 501, 'Asha', '560001', 'Bengaluru'), (4, 12, 'Marker', 35, 1, 503, 'Meera','411001', 'Pune'); """) # Update anomaly: rename a product but only touch one row db.execute("UPDATE sales_1nf SET product_name = 'Spiral Notebook' WHERE order_id = 1 AND product_id = 10") print(db.execute("SELECT DISTINCT product_id, product_name FROM sales_1nf WHERE product_id = 10").fetchall()) # Delete anomaly: cancel order 4 and lose the Marker product db.execute("DELETE FROM sales_1nf WHERE order_id = 4") print(db.execute("SELECT * FROM sales_1nf WHERE product_id = 12").fetchall()) # Insert anomaly: a new product with no order cannot be stored try: db.execute("INSERT INTO sales_1nf (product_id, product_name, unit_price) VALUES (13, 'Eraser', 5)") except sqlite3.IntegrityError as e: print("insert failed:", e)[(10, 'Spiral Notebook'), (10, 'Notebook')] [] insert failed: NOT NULL constraint failed: sales_1nf.order_id

- **Update anomaly:** product 10 now has two names. The name is repeated on every row that contains it, and the update touched only one row.
- **Delete anomaly:** cancelling order 4 removed the only record that the Marker product exists, along with its price.
- **Insert anomaly:** an Eraser that nobody has ordered yet cannot be stored, because order_id is part of the key and cannot be NULL.

SQLite note: the table declares order_id and product_id as NOT NULL. In SQLite a composite PRIMARY KEY does not imply NOT NULL for ordinary rowid tables, so without that clause the Eraser row would have been accepted with a NULL order. [SQLite's CREATE TABLE documentation](https://www.sqlite.org/lang_createtable.html) calls this a historical bug kept for compatibility. MySQL and PostgreSQL always enforce NOT NULL on primary key columns.

## 2NF and 3NF: split until every fact lives once

Three dependencies hide in sales_1nf. product_id alone determines the name and price (a partial dependency on the key, so a 2NF problem). order_id alone determines the customer. And the customer determines the pincode, which determines the city. That last chain is a transitive dependency, the 3NF problem. We assume one pincode maps to one city for this example.

| Step | Tables after the split | What was removed |
|---|---|---|
| 2NF | products(product_id, name, unit_price), orders2(order_id, customer..., city), order_items(order_id, product_id, qty) | Facts about a product or an order repeated per line |
| 3NF | pincodes, customers, orders, order_items, products | Facts about a customer's location repeated per order |

The script does both steps with INSERT ... SELECT DISTINCT, then proves the decomposition is lossless by rebuilding the flat table with joins and comparing it with the original using EXCEPT in both directions. Empty results on both sides mean no rows were lost or invented.import sqlite3 db = sqlite3.connect(":memory:") db.executescript(""" CREATE TABLE sales_1nf ( order_id INTEGER NOT NULL, product_id INTEGER NOT NULL, product_name TEXT, unit_price INTEGER, qty INTEGER, customer_id INTEGER, customer_name TEXT, pincode TEXT, city TEXT, PRIMARY KEY (order_id, product_id)); INSERT INTO sales_1nf VALUES (1, 10, 'Notebook', 60, 3, 501, 'Asha', '560001', 'Bengaluru'), (1, 11, 'Pen', 10, 5, 501, 'Asha', '560001', 'Bengaluru'), (2, 10, 'Notebook', 60, 2, 502, 'Ravi', '411001', 'Pune'), (3, 11, 'Pen', 10, 8, 501, 'Asha', '560001', 'Bengaluru'), (4, 12, 'Marker', 35, 1, 503, 'Meera','411001', 'Pune'); -- 2NF: remove attributes that depend on only part of the key CREATE TABLE products (product_id INTEGER PRIMARY KEY, product_name TEXT, unit_price INTEGER); CREATE TABLE orders2 (order_id INTEGER PRIMARY KEY, customer_id INTEGER, customer_name TEXT, pincode TEXT, city TEXT); CREATE TABLE order_items (order_id INTEGER, product_id INTEGER, qty INTEGER, PRIMARY KEY (order_id, product_id)); INSERT INTO products SELECT DISTINCT product_id, product_name, unit_price FROM sales_1nf; INSERT INTO orders2 SELECT DISTINCT order_id, customer_id, customer_name, pincode, city FROM sales_1nf; INSERT INTO order_items SELECT order_id, product_id, qty FROM sales_1nf; -- 3NF: remove transitive dependencies (order -> customer -> pincode -> city) CREATE TABLE pincodes (pincode TEXT PRIMARY KEY, city TEXT); CREATE TABLE customers (customer_id INTEGER PRIMARY KEY, customer_name TEXT, pincode TEXT REFERENCES pincodes(pincode)); CREATE TABLE orders (order_id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(customer_id)); INSERT INTO pincodes SELECT DISTINCT pincode, city FROM sales_1nf; INSERT INTO customers SELECT DISTINCT customer_id, customer_name, pincode FROM sales_1nf; INSERT INTO orders SELECT DISTINCT order_id, customer_id FROM sales_1nf; """) for t in ("pincodes", "customers", "orders", "order_items", "products"): print(t, db.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0], "rows") # Rebuild the flat table with joins and compare with the original (both directions) flat = """ SELECT oi.order_id, oi.product_id, p.product_name, p.unit_price, oi.qty, c.customer_id, c.customer_name, c.pincode, pc.city FROM order_items oi JOIN products p ON p.product_id = oi.product_id JOIN orders o ON o.order_id = oi.order_id JOIN customers c ON c.customer_id = o.customer_id JOIN pincodes pc ON pc.pincode = c.pincode""" print("lost rows:", db.execute(f"SELECT * FROM sales_1nf EXCEPT {flat}").fetchall()) print("extra rows:", db.execute(f"{flat} EXCEPT SELECT * FROM sales_1nf").fetchall()) # The anomalies are gone db.execute("UPDATE products SET product_name = 'Spiral Notebook' WHERE product_id = 10") # one row, one place db.execute("INSERT INTO products VALUES (13, 'Eraser', 5)") # no order needed db.execute("DELETE FROM order_items WHERE order_id = 4") # Marker survives print(db.execute("SELECT product_name FROM products WHERE product_id IN (10, 12, 13) ORDER BY 1").fetchall())pincodes 2 rows customers 3 rows orders 4 rows order_items 5 rows products 3 rows lost rows: [] extra rows: [] [('Eraser',), ('Marker',), ('Spiral Notebook',)]

The same three operations that failed earlier now work: renaming a product touches one row, a new product needs no order, and deleting an order line leaves the product intact. Joins cost a little more at read time, which is the trade covered below. If joins are new to you, read [SQL joins explained](https://www.masaischool.com/resources/sql-joins-explained-with-examples) first.

Two design notes. First, a real shop stores the price paid on the order line, because products.unit_price changes over time and an old invoice must not change with it. That is not a violation: the order line's price is a different fact (the price at purchase) from the catalogue price. Second, SQLite does not enforce the REFERENCES clauses above unless you run PRAGMA foreign_keys = ON for each connection, as [its foreign key documentation](https://www.sqlite.org/foreignkeys.html) explains. MySQL with InnoDB and PostgreSQL enforce them by default.

## BCNF: when 3NF is not enough

Boyce-Codd Normal Form (BCNF) is a stricter 3NF. It catches tables with more than one candidate key where the keys overlap. The classic case: students enrol in courses, each course can have several teachers, but each teacher teaches exactly one course. So teacher determines course, yet teacher is not a key of (student, course, teacher). This table is in 3NF, because course is part of a candidate key, but it is not in BCNF.import sqlite3 db = sqlite3.connect(":memory:") db.executescript(""" -- Rule: each teacher teaches exactly one course (teacher -> course). -- Keys: (student, course) and (student, teacher). teacher is NOT a key. CREATE TABLE enrol (student TEXT, course TEXT, teacher TEXT, PRIMARY KEY (student, course)); INSERT INTO enrol VALUES ('Asha', 'Databases', 'Rao'), ('Ravi', 'Databases', 'Rao'), ('Asha', 'Networks', 'Iyer'); """) # Contradiction nothing prevents: Rao now "teaches" two courses db.execute("INSERT INTO enrol VALUES ('Ravi', 'Networks', 'Rao')") print(db.execute("SELECT DISTINCT teacher, course FROM enrol WHERE teacher = 'Rao' ORDER BY course").fetchall()) db.execute("DELETE FROM enrol WHERE teacher = 'Rao'") # undo the bad row and the genuine ones # Delete anomaly: removing Rao's students also removes the fact that Rao teaches Databases print("Rao teaches:", db.execute("SELECT course FROM enrol WHERE teacher = 'Rao'").fetchall()) # BCNF decomposition db.executescript(""" CREATE TABLE teacher_course (teacher TEXT PRIMARY KEY, course TEXT); CREATE TABLE student_teacher (student TEXT, teacher TEXT, PRIMARY KEY (student, teacher)); INSERT INTO teacher_course VALUES ('Rao', 'Databases'), ('Iyer', 'Networks'); INSERT INTO student_teacher VALUES ('Asha', 'Rao'), ('Ravi', 'Rao'), ('Asha', 'Iyer'); """) try: db.execute("INSERT INTO teacher_course VALUES ('Rao', 'Networks')") except sqlite3.IntegrityError as e: print("blocked:", e) # The price: the old rule 'a student takes a course from one teacher only' is no longer a key. db.executescript("INSERT INTO teacher_course VALUES ('Nair', 'Databases'); INSERT INTO student_teacher VALUES ('Asha', 'Nair');") print(db.execute("""SELECT st.student, tc.course, COUNT(*) AS teachers FROM student_teacher st JOIN teacher_course tc USING (teacher) GROUP BY 1, 2 HAVING COUNT(*) > 1""").fetchall())[('Rao', 'Databases'), ('Rao', 'Networks')] Rao teaches: [] blocked: UNIQUE constraint failed: teacher_course.teacher [('Asha', 'Databases', 2)]

The first line is a contradiction the table cannot prevent: Rao now appears to teach two courses. The second is a delete anomaly: removing Rao's students removed the fact that Rao teaches Databases. After decomposing into teacher_course(teacher PRIMARY KEY, course) and student_teacher(student, teacher), the primary key blocks the contradiction, as the blocked: line shows.

BCNF has a price. The original rule that a student takes each course with only one teacher can no longer be declared as a key in either table, so the last query finds Asha with two Databases teachers. You would need a trigger, an assertion or application code. This is why textbooks say BCNF decomposition may not preserve all dependencies, and why many practical schemas stop at 3NF and accept a rare BCNF violation. In an interview, say both halves: BCNF removes the anomaly, and it can cost you an enforceable rule.

## When to denormalise, and how to do it safely

Denormalise on purpose, after measuring, and never as a first draft. Common reasons are read-heavy dashboards, reports that join many tables, and data warehouses where history must not change. The safest pattern keeps the normalised tables as the source of truth and builds a separate summary table from them.import sqlite3 db = sqlite3.connect(":memory:") db.executescript(""" CREATE TABLE customers (customer_id INTEGER PRIMARY KEY, name TEXT); CREATE TABLE orders (order_id INTEGER PRIMARY KEY, customer_id INTEGER, order_total INTEGER); INSERT INTO customers VALUES (1, 'Asha'), (2, 'Ravi'); INSERT INTO orders VALUES (1, 1, 450), (2, 1, 100), (3, 2, 120); -- Denormalised summary: one row per customer, built for a dashboard CREATE TABLE customer_summary AS SELECT c.customer_id, c.name, COUNT(*) AS orders, SUM(o.order_total) AS revenue FROM customers c JOIN orders o USING (customer_id) GROUP BY c.customer_id; """) print(db.execute("SELECT * FROM customer_summary").fetchall()) db.execute("INSERT INTO orders VALUES (4, 1, 300)") # a new order arrives print("summary:", db.execute("SELECT revenue FROM customer_summary WHERE customer_id = 1").fetchone()) print("truth :", db.execute("SELECT SUM(order_total) FROM orders WHERE customer_id = 1").fetchone())[(1, 'Asha', 2, 550), (2, 'Ravi', 1, 120)] summary: (550,) truth : (850,)

The summary shows 550 for Asha after a new 300 order arrived, while the truth is 850. A denormalised copy is a cache, so it needs a refresh plan: a scheduled rebuild, a trigger, or a materialised view (PostgreSQL has CREATE MATERIALIZED VIEW; SQLite and MySQL do not).

| Situation | Keep normalised | Denormalise |
|---|---|---|
| Many writes, few reads (orders, payments) | Yes | No |
| Dashboard reading millions of rows by customer | Source tables | Summary table with a refresh job |
| Value must never change retroactively (price at purchase) | Store a snapshot on the line | This is a snapshot, not duplication |
| Document stores such as MongoDB | Not required | Embedding is the normal pattern |

For where this fits in a data job, see [data analytics learning path](https://www.masaischool.com/resources/data-analytics) and [free data analytics tools](https://www.masaischool.com/resources/tools/free-data-analytics-tools). For a project that forces you to design a schema, try the ideas in [software development projects](https://www.masaischool.com/resources/projects/software-development-projects).

## Frequently asked questions

### What is normalization in DBMS in simple words?

Normalization is organising a database so each fact is stored in one place only. You split wide tables into smaller related ones and link them with keys. This prevents the same product name or city being typed in many rows and getting out of sync, and it stops inserts and deletes from losing unrelated information.

### What is the difference between 2NF and 3NF?

2NF removes partial dependencies: a column that depends on only part of a composite key, like a product name in an order-line table. 3NF removes transitive dependencies: a column that depends on another non-key column, like city depending on pincode. A table with a single-column key cannot have a 2NF problem but can still have a 3NF one.

### What is the difference between 3NF and BCNF?

3NF allows a dependency X to Y when Y is part of a candidate key. BCNF does not: X must itself be a candidate key. The two differ only when a table has overlapping candidate keys. BCNF removes slightly more redundancy, but the decomposition can make some original rules impossible to declare as keys.

### What are update, insert and delete anomalies?

They are errors caused by redundancy. An update anomaly leaves the same fact with two values. An insert anomaly stops you recording a fact because an unrelated value is missing. A delete anomaly loses a fact when you remove a row that was its only record. The worked example above triggers all three with output.

### Is a fully normalised database always better?

No. Normalised tables are best for write-heavy systems where consistency matters. Read-heavy reporting often uses denormalised summary tables or a warehouse to avoid expensive joins. Measure the query first, keep the normalised tables as the source of truth, and refresh any copy on a schedule or with a trigger.

### How many normal forms are there?

Textbooks and interviews mostly cover 1NF, 2NF, 3NF and BCNF. Higher forms exist: 4NF handles multi-valued dependencies, 5NF handles join dependencies, and 6NF is used in temporal databases. Real projects almost never go beyond 3NF or BCNF, so learn those four thoroughly first.

### Do NoSQL databases need normalization?

Document databases such as MongoDB usually favour embedding related data in one document, which is deliberate denormalisation for read speed. You still need to think about which data changes together and which is shared. See the [types of databases](https://www.masaischool.com/resources/types-of-databases-explained) page for when each model fits.
