Database normalization organizes columns and tables to minimize duplicate data (redundancy) and prevent anomalies during insert, update, and delete operations.
1NF: Atomic values in each column; unique records.
2NF: In 1NF and no partial dependencies on composite keys.
3NF: In 2NF and no transitive dependencies.
💡 Key Takeaways: SQL Database Normalization
Mastering SQL Database Normalization helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SQL Database Normalization Code Example
SQL
-- Normalized order items table referencing orders and products
CREATE TABLE order_items (
order_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
unit_price DECIMAL(10,2) NOT NULL,
PRIMARY KEY (order_id, product_id),
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
Output
Creates 3NF-compliant bridge table for order lines