Database Normalization Basics


Database Normalization Basics

Corey
Hey Maria, I was reading about databases and keep hearing about normalization. Isn't that just for making tables neat?

Maria
Well, it's more than neatness. Normalization prevents weird data inconsistencies—like one customer having two different birthdays. That's a failure of data integrity.

Corey
Oh, so it's about avoiding contradictions? But how does that work in practice?

Maria
Exactly. We structure tables so they can't hold redundant info. There are normal forms—like safety levels for a bridge. First normal form is the basic level; fifth is the strictest.

Corey
Okay, let's start with First Normal Form. What makes a table fail that?

Maria
Four things. First, using row order to convey meaning—like listing The Beatles from tallest to shortest without a height column. Tables don't have a guaranteed order.

Corey
Right, so you should just add a height column. What else?

Maria
Mixing data types in one column is another no-no. You can't have some heights as integers and some as strings. And every table needs a primary key to uniquely identify rows.

Corey
And the fourth rule? Something about repeating groups?

Maria
Yeah—like storing a player's entire inventory list in one text column or multiple columns for each item type. Instead, you break it into separate rows: each row is one player and one item type.

Corey
So that's First Normal Form. What about Second Normal Form? That sounds trickier.

Maria
It deals with part-key dependencies. Suppose you have a player inventory table with a primary key of (Player, Item). If you add Player Rating, that depends only on Player, not the whole key.

Corey
And that causes problems?

Maria
Yep. Deletion anomaly: if a player loses all items, you lose their rating too. Update anomaly: update only one row and you get contradictory ratings. Insertion anomaly: can't add a new player with no items.

Corey
So the fix is to split the table into two: one for players and ratings, one for inventory. Then each non-key attribute depends on the full key. That's Second Normal Form.

Maria
Exactly. Now Third Normal Form is about transitive dependencies. Say your Player table has Skill Level and Rating, where Rating depends on Skill Level, not directly on the player ID.

Corey
So if skill level changes and you forget to update rating, you get inconsistency.

Maria
Right. The rule: every non-key attribute must depend on the key, the whole key, and nothing but the key. If you also drop 'non-key', you get Boyce-Codd Normal Form, which is slightly stricter but rarely different in practice.

Corey
That covers most real-world cases, right? But there's Fourth and Fifth Normal Forms too.

Maria
Yeah, for special cases. Fourth Normal Form handles multivalued dependencies. Like a birdhouse site: each model has a set of colors and a set of styles, independently. If you combine them in one table, you get duplicates and anomalies when adding a new color.

Corey
So you split into two tables: one for model-colors, one for model-styles. That way, no multivalued dependency except on the key.

Maria
Bingo. And Fifth Normal Form is even rarer. It's about join dependencies. Example: people, brands, and flavors. If you combine all three into one table, updating likes for a new brand can lead to missing combinations.

Corey
So you split into three tables: brand-flavor, person-brand, person-flavor. Then join them when needed. That avoids logical inconsistencies.

Maria
Exactly. Fifth Normal Form says the table shouldn't be reconstructable from joining smaller ones. If it is, you should decompose it.

Corey
So normalization is all about avoiding anomalies by ensuring each fact is stored exactly once. Great summary!

Maria
Right. And remember the golden rule: every attribute should depend on the key, the whole key, and nothing but the key. That gets you to 3NF or BCNF, which covers 99% of cases.

Ask anything
We've read this whole study set, so questions about it get the best answers.