Skip to the solution
MediumDSA15 min read

What is database normalization?

1.2k views

The problem

Question presented to candidate: "What is database normalization? Walk me through 1NF, 2NF and 3NF with an example, and tell me what problems normalization actually prevents."

What a strong answer should cover:

  • Normalization is the process of splitting tables so that each fact is stored once, in the table whose key it depends on, to remove redundancy and the update, insert and delete anomalies it causes
  • The normal forms as rules about keys and functional dependencies: 1NF (atomic values, no repeating groups), 2NF (no non-key column depends on only part of a composite key), 3NF (no non-key column depends on another non-key column), BCNF (every determinant is a candidate key)
  • A concrete decomposition: a flat orders sheet split into customers, products, orders and order_items, joined back with foreign keys and no information lost
  • Subtle modelling points: a price at the time of sale belongs on the order line, not on the product; a repeated value is not always redundancy
  • Trade-off: more tables and joins on reads, cleaner writes and constraints; most OLTP schemas aim for 3NF and denormalize deliberately where reads demand it

Code / implementation expected: Optional β€” queries that expose redundancy in a flat table, and the normalized tables joined back into the same report.

Schema used by the examples:

  • normalization

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

15 min read Β· 9 sections

Run the code

Edit the query and run it against the tables for this question.

SQLUpdate anomaly: the flat table now holds two different emails for the same customer
SQLTest a functional dependency: does product_sku decide the name and the price?
SQLThe normalized tables joined back into the same order report

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 17 of 82 in SQL

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All SQL questions
Up nextMedium

Advanced UPSERT patterns β€” conditional updates, xmax detection, and soft-delete-aware indexes?

Continue