Database Normalization: Tidy Tables, Less Redundancy
Database normalization organizes data into smaller, related tables to eliminate redundancy, like separating addresses from orders. It's the standard for transactional (OLTP) systems where data integrity is critical.
WHY IT EXISTS Without normalization, databases suffer from update, insertion, and deletion anomalies. If a customer's address is stored with every order, changing it requires updating multiple rows, and you might miss one (update anomaly). If a customer hasn't placed an order yet, their details might have nowhere to live (insertion anomaly). Deleting a customer's only order could erase their existence from the database entirely (deletion anomaly).
THE MENTAL MODEL Normalization is like organizing a messy closet into a well-structured dresser. An unnormalized database is one giant pile on the floor. First Normal Form (1NF) is ensuring every item is distinct—no shirt-and-pants combos. Second and Third Normal Forms (2NF, 3NF) are like creating separate drawers for 'shirts' and 'pants' and using foreign keys (like labels) to link them into outfits. This reduces repetition and makes it easy to find and update a single source of truth.
HOW IT WORKS Normalization is a formal process of following rules called Normal Forms. The most common are: 1NF (First Normal Form): Ensures all column values are atomic (indivisible) and each row is unique, typically with a primary key. 2NF (Second Normal Form): Must be in 1NF. All non-key attributes must depend on the whole primary key. This prevents redundancy in tables with composite keys. 3NF (Third Normal Form): Must be in 2NF. All attributes must depend only on the primary key, not on other non-key attributes. For example, don't store 'city' if it can be looked up from 'zip_code'. Put zip codes and cities in their own table. Most well-designed relational databases aim for 3NF.
WHEN TO USE IT Use normalization for Online Transaction Processing (OLTP) systems—the databases powering most web applications, e-commerce sites, and SaaS products. In these systems, data integrity and avoiding modification anomalies are paramount. It's the default for relational databases like PostgreSQL and MySQL.
WHEN NOT TO USE IT Avoid aggressive normalization in Online Analytical Processing (OLAP) systems or data warehouses. For analytics, performance on large, complex read queries is key. Denormalized schemas are often used intentionally to reduce the number of JOINs and speed up reporting. Similarly, NoSQL document databases often favor embedding related data (denormalization) for read performance.
ONE CANONICAL EXAMPLE An unnormalized table might store (order_id, customer_name, customer_address, product_name, product_price). The customer's address is repeated for every order they place. A normalized approach creates separate tables: Customers (customer_id, name, address), Products (product_id, name, price), and Orders (order_id, customer_id, order_date). An Order_Items table then links orders to products (order_id, product_id, quantity). Now, a customer's address exists in only one place.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.