-- BAD: product_name depends only on product_id, not (order_id, product_id)-- order_items(order_id, product_id, qty, product_name)-- 2NF: move product_name to productsCREATE TABLE products (id BIGSERIAL PK, name TEXT);CREATE TABLE order_items ( order_id BIGINT, product_id BIGINT, qty INT, PRIMARY KEY (order_id, product_id));
4. Applying Third Normal Form
3NF Rule
Requirement
Must be 2NF
Already satisfies 2NF
No Transitive Dependencies
Non-key attrs depend only on PK
Test
For each non-trivial FD X→A, X must be superkey OR A part of candidate key
Example: Removing Transitive Dependency
-- BAD: zip → city, state (transitive via zip)-- customer(id, name, zip, city, state)-- 3NFCREATE TABLE zip_codes (zip CHAR(5) PRIMARY KEY, city TEXT, state CHAR(2));CREATE TABLE customers (id BIGSERIAL PK, name TEXT, zip CHAR(5) REFERENCES zip_codes(zip));
5. Applying Boyce-Codd Normal Form (BCNF)
BCNF Rule
Requirement
Must be 3NF
Stricter form of 3NF
Determinant is Superkey
For every non-trivial FD X→Y, X must be superkey
When Matters
Overlapping candidate keys exist
6. Applying Fourth Normal Form
4NF Rule
Requirement
Must be BCNF
Plus eliminate MVDs
No Multi-valued Dependencies
Independent multi-valued facts in separate tables
Note: If student → courses and student → hobbies are independent, put them in separate tables — not a single (student, course, hobby) table.
7. Applying Fifth Normal Form
5NF Rule
Requirement
Must be 4NF
Plus no join dependencies that aren't implied by keys
Decomposable
Cannot lose info when splitting/rejoining tables
Rare in Practice
Mostly theoretical concern
8. Identifying Normalization Anomalies
Anomaly
Symptom
Caused By
Insert Anomaly
Can't add data without unrelated data
Missing entity decomposition
Update Anomaly
Same fact in multiple rows; partial updates
Redundancy
Delete Anomaly
Removing row loses unrelated info
Coupled entities
Redundancy
Same data stored in many rows
Lack of decomposition
9. Using Normalization Tools and Techniques
Tool
Purpose
ERwin / ER/Studio
ER modeling with normalization
dbdiagram.io / DrawSQL
Schema diagrams with FK detection
DBeaver / DataGrip
Reverse-engineer + FD discovery
SchemaSpy
Generates schema docs, finds anomalies
Synthesis Algorithm
3NF synthesis from FDs
Decomposition Algorithm
BCNF lossless-join decomposition
10. Balancing Normalization vs Performance
Goal
Approach
OLTP (writes)
3NF/BCNF — minimize redundancy, fast updates
OLAP (reads)
Star/snowflake — denormalize fact tables
Hybrid (HTAP)
Normalized core + materialized read views
Trade-off
More joins (normalized) vs more storage + update cost (denormalized)
Warning: Don't denormalize until profiling proves a normalized schema is too slow. Premature denormalization creates data integrity bugs.