Database Normalization
Definition
Database normalization is the process of organizing a relational database to reduce data redundancy and improve data integrity by decomposing tables according to normal form rules.
Introduction to Database Normalization
Normalization is the art of designing relational databases that don't lie. A poorly normalized database allows contradictory data to exist (the same customer's address stored in two places with different values). Normal forms (1NF through BCNF) provide a systematic framework for eliminating these anomalies.
Syntax
-- Example: Denormalized orders table (bad) CREATE TABLE orders_bad ( order_id INT, customer_name VARCHAR(100), -- redundant customer_email VARCHAR(100), -- redundant product_name VARCHAR(100), -- redundant product_price DECIMAL(10,2) -- redundant ); -- Normalized (good) CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100)); CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2)); CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT REFERENCES customers(id), product_id INT REFERENCES products(id));
Examples
First Normal Form (1NF)
-- VIOLATION: multi-valued column CREATE TABLE students_bad ( id INT, name VARCHAR(100), courses VARCHAR(500) -- 'Math, Science, English' -- WRONG ); -- 1NF COMPLIANT: atomic values CREATE TABLE student_courses ( student_id INT, course_name VARCHAR(100), PRIMARY KEY (student_id, course_name) );
1NF requires atomic (indivisible) column values. Storing comma-separated lists violates 1NF. Create a separate table with one row per student-course combination.
Try in PlaygroundThird Normal Form (3NF)
-- VIOLATION: transitive dependency CREATE TABLE employees_bad ( emp_id INT, emp_name VARCHAR(100), dept_id INT, dept_name VARCHAR(100) -- depends on dept_id, not emp_id -- WRONG ); -- 3NF COMPLIANT: separate departments CREATE TABLE employees (emp_id INT PRIMARY KEY, emp_name VARCHAR(100), dept_id INT); CREATE TABLE departments (dept_id INT PRIMARY KEY, dept_name VARCHAR(100));
3NF requires that non-key columns depend only on the primary key, not on other non-key columns. dept_name depends on dept_id (not emp_id), so it belongs in a departments table.
Try in PlaygroundCommon Mistakes
Over-normalizing — splitting tables too finely leads to excessive JOINs and poor read performance
Not indexing foreign keys after normalization
Confusing 2NF (no partial dependency on composite key) with 3NF (no transitive dependency)
Ignoring normalization entirely — denormalized databases develop update anomalies and inconsistencies
Frequently Asked Questions
What is database normalization?
What are the normal forms in database design?
When should you denormalize a database?
What is the difference between 2NF and 3NF?
Related SQL Topics
Practice This in the SQL Playground
Write real queries, see live results, and master Database Normalization hands-on. 100% free.