← Back to SQL, page 10

sql-0197 · Easy fresher

What is normalization, and which problems does it solve?

Normalization organizes tables so each fact is stored once, by splitting data according to its dependencies. It prevents update anomalies (changing a fact in one row but not another), insert anomalies (being unable to record a fact without an unrelated one) and delete anomalies (losing a fact when deleting another).

Full answer

Picture one wide table of enrolments that also repeats the student's city and the course title on every row.

  • Update anomaly: Asha moves, and the city must be changed on every one of her enrolment rows. Miss one and the data contradicts itself.
  • Insert anomaly: a new course cannot be recorded until someone enrols, because the row needs a student.
  • Delete anomaly: removing the last enrolment in Ethics also deletes the only record that Ethics exists.

Splitting into students, courses and enrolments stores each fact once and connects them by keys, which is how the SCHOOL sample schema in this bank is laid out.

The normal forms (1NF, 2NF, 3NF, BCNF) are a checklist for this process. Each removes one kind of redundant dependency. Most transactional systems aim for 3NF or BCNF and denormalize selectively for read performance.

Key points

  • Normalization stores each fact once
  • It prevents update, insert and delete anomalies
  • Tables are split by functional dependencies
  • Most OLTP schemas target 3NF or BCNF

Common mistakes

  • Defining normalization as 'splitting tables' without saying why
  • Normalizing so far that simple reads need many joins without need

Follow-ups

  • What does 1NF require?
  • When is denormalization justified?

Tips

  • Give one example of each anomaly