What is database normalization and how far should I go?

posée 3 months ago415 vuesen

0

My teacher talks about 1NF, 2NF, 3NF. In real projects, do people actually normalize? When is denormalizing OK?

Diagnostic IA

Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.

posée 3 months ago

1 réponse

7
✓
✓ Réponse acceptée

Normalization means storing each fact once, so updates can't leave contradictory copies.

- 1NF: no repeating groups. Not phone1, phone2, phone3 columns, but a phones table. - 2NF/3NF: every non-key column depends on *the key, the whole key, and nothing but the key*. Don't store customer_city in orders; reference customers.

In practice, design to 3NF by default. It prevents a whole class of data bugs.

Denormalize deliberately when you've measured a read-performance need. Typical cases: - cached counters (answer_count on questions), kept in sync in the same transaction or by a trigger; - snapshots that *should* be frozen, such as the price on an invoice line (the product price can change later); - read models, materialized views, or analytics tables.

If you denormalize, document the source of truth and how the copy is kept in sync.

Connectez-vous pour dire si ça a marché.

answered 3 months ago

Sign in and verify your email to post an answer.