What is Database Normalization? Why It Matters
SQL • Concepts Explained • 6 min read
Database normalization organizes data to reduce redundancy. Learn the normal forms and when to apply them.
Database normalization organizes data to reduce redundancy and improve integrity. It's a fundamental concept in database design that every developer should understand.
The Problem Normalization Solves
Without normalization, you might store the same data in multiple places. If a customer changes their address, you'd have to update it everywhere. Normalization fixes this.
Normal Forms
First Normal Form (1NF)
Each cell contains one value, and each record is unique:
-- Bad: Multiple values in one cell
CREATE TABLE orders (
id INT,
products TEXT -- "Laptop, Mouse, Keyboard"
);
-- Good: Each value in its own row
CREATE TABLE orders (
id INT,
product VARCHAR(100)
);
Second Normal Form (2NF)
Must be in 1NF, and all non-key columns depend on the entire primary key:
-- Bad: product_name depends only on product_id, not order_id
CREATE TABLE order_items (
order_id INT,
product_id INT,
product_name VARCHAR(100) -- Redundant!
);
-- Good: Separate tables
CREATE TABLE order_items (
order_id INT,
product_id INT,
quantity INT
);
CREATE TABLE products (
id INT,
name VARCHAR(100)
);
Third Normal Form (3NF)
Must be in 2NF, and no transitive dependencies:
-- Bad: city depends on zip_code, not directly on customer_id
CREATE TABLE customers (
id INT,
name VARCHAR(100),
zip_code VARCHAR(10),
city VARCHAR(100) -- Transitive dependency
);
-- Good: Separate table
CREATE TABLE customers (
id INT,
name VARCHAR(100),
zip_code VARCHAR(10)
);
CREATE TABLE zip_codes (
zip_code VARCHAR(10),
city VARCHAR(100)
);
Benefits of Normalization
- Less redundancy — Data stored once
- Better integrity — Updates happen in one place
- Smaller database — Less storage needed
- Easier maintenance — Changes are simpler
When to Denormalize
Sometimes you break normalization rules for performance. If you frequently join tables for read-heavy applications, denormalizing can speed up queries.
Note: Learn normalization to understand good database design, but don't apply it dogmatically. Real-world databases often balance normalization with performance needs.