What is database normalization and what are 1NF, 2NF, and 3NF?
Normalization is the process of structuring a relational database schema to reduce data redundancy, prevent update anomalies, and improve data integrity.
• 1NF (First Normal Form): Every column contains atomic (indivisible) values, each record is unique, and no repeating groups exist. • 2NF (Second Normal Form): Meets 1NF, and all non-key attributes are fully functionally dependent on the entire primary key (no partial key dependencies). • 3NF (Third Normal Form): Meets 2NF, and non-key attributes are not transitively dependent on the primary key (no non-key attribute depends on another non-key attribute).
-- 3NF Design: Separating Customers and Orders to eliminate redundancy
CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL
);
CREATE TABLE Orders (
order_id INT PRIMARY KEY,
customer_id INT REFERENCES Customers(customer_id),
order_date DATE NOT NULL,
total_amount DECIMAL(10, 2) NOT NULL
);By keeping customer details in `Customers` and referencing `customer_id` from `Orders`, changing a customer's email only requires updating one row instead of thousands of past order rows.
Ready for Window Functions?
Take a quick test to evaluate yourself, or move straight to the next module.