Databases

Normalization

Normalization separates facts by subject so that the same information is not stored repeatedly. Redundancy can cause inconsistent data when updating, inserting, or deleting rows.

A simulator showing how 1NF, 2NF, and 3NF resolve data anomalies

1. Choose a normal form

2. Try an operation that exposes an anomaly

Change the normal form, then repeat the same operation. An operation that affects many rows or cannot be performed in 1NF may require only one change after decomposition. Underlined columns form the primary key.

1NFOne value per cell
2NFNo partial dependencies
3NFNo transitive dependencies
BCNFEvery determinant is a candidate key

Use functional dependencies to choose decompositions

Student ID → Name means that a student ID determines one name. The colored chips show functional dependencies. Normalization moves related facts into separate tables; as you advance, chips of the same color gather in the same table.

1NF keeps one value in each cell. 2NF removes dependencies on part of a composite key: a name depends only on student_id, while a course name depends only on course_code. 3NF removes dependencies through another non-key column, such as Student ID → Department → Office. BCNF goes further: every determinant must be a candidate key.

Practice and interviews

Further normalization reduces redundancy but can require more JOINs when reading data. Read-heavy systems sometimes deliberately denormalize selected facts. Be ready to explain update, insertion, and deletion anomalies with examples and show how decomposition prevents them.