Database Normalization: 1NF to 3NF
Normalization organizes data to reduce redundancy and improve integrity. The three main normal forms (1NF, 2NF, 3NF) progressively eliminate different types of data anomalies.
First Normal Form (1NF)
Rule: Each cell contains a single value, no repeating groups.
Before 1NF (Bad)
| customer_id | name | phones |
|-------------|-------|---------------------|
| 1 | Alice | 555-0001, 555-0002 |
After 1NF (Good)
| customer_id | name | phone |
|-------------|-------|----------|
| 1 | Alice | 555-0001 |
| 1 | Alice | 555-0002 |
Second Normal Form (2NF)
Rule: Must be in 1NF, and no partial dependencies (all non-key columns depend on the entire primary key).
Before 2NF (Bad)
-- Primary key is (order_id, product_id)
| order_id | product_id | customer_name | product_name |
|----------|------------|---------------|--------------|
| 1 | 101 | Alice | Widget |
-- customer_name depends only on order_id, not full key!
After 2NF (Good)
-- Orders table
| order_id | customer_name |
|----------|---------------|
| 1 | Alice |
-- Order_items table
| order_id | product_id | product_name |
|----------|------------|--------------|
| 1 | 101 | Widget |
Third Normal Form (3NF)
Rule: Must be in 2NF, and no transitive dependencies (non-key columns can't depend on other non-key columns).
Before 3NF (Bad)
| employee_id | name | dept_id | dept_name |
|-------------|-------|---------|--------------|
| 1 | Alice | 10 | Engineering |
-- dept_name depends on dept_id, not employee_id!
After 3NF (Good)
-- Employees table
| employee_id | name | dept_id |
|-------------|-------|---------|
| 1 | Alice | 10 |
-- Departments table
| dept_id | dept_name |
|---------|--------------|
| 10 | Engineering |
Benefits of Normalization
- Eliminates data redundancy
- Prevents update anomalies
- Improves data consistency
- Makes database structure clearer
Pro Tip: Normalize to 3NF for transactional databases. For analytical/reporting databases, denormalization can improve query performance. Know when to break the rules!
← Back to SQL Tips