CodeGym /Courses /SQL SELF /Introduction to Data Normalization

Introduction to Data Normalization

SQL SELF
Level 25 , Lesson 0
Available

Ever seen a database table that looked like a junk drawer? One cell has a list of phone numbers, another has addresses written as one long sentence, and a third has a bunch of dates separated by commas. That kind of "chaos" makes searching, updating, and managing data a pain. But there’s a way to bring order to the madness. It’s called data normalization.

Simply put, data normalization is the process of organizing data in tables to minimize data redundancy and get rid of problems that come up when updating, deleting, or inserting data.

Here’s what data normalization helps with:

  1. Eliminating duplicate data. Why store the same info twice? Or three times? That just bloats your database and leads to inconsistent data.
  2. Minimizing anomalies. You know how in real life you sometimes forget to delete an ex-coworker from your contacts? That happens in databases too. Normalization helps you avoid those awkward moments.
  3. Simplifying data structure. The simpler the structure, the easier it is to manage.
  4. Speeding up the database. Less data means faster queries.

So what if you skip normalization?

Without normalization, your data gets "sticky"—it keeps dragging along extra bits of info you don’t really need.

Imagine a Students table:

Student ID Name Courses
1 Otto Lin Mathematics, Physics
2 Anna Song Chemistry
3 Otto Lin Biology, Chemistry

What could go wrong:

  • Duplicate data: Otto Lin shows up more than once. Why? Because he’s taking multiple courses.
  • Hard to update info: if Otto Lin’s phone number changes, you have to hunt down every record with his name to update it.
  • Deleting data can break things: imagine Otto decides to drop his courses. If you delete all his rows, you lose all info about him, including his name.

When can normalization be too much?

Let’s be real, normalization is like a strict schedule: usually great, but sometimes you just want to be spontaneous. There are times when denormalization is actually better:

  1. In analytical databases, where query speed matters more than minimizing data size.
  2. When the structure gets too complicated: if following normal forms means juggling dozens of tables, your queries will get more and more unwieldy.
  3. For frequently used aggregates: if you’re always calculating the same sum, it’s better to just store it.

Say you’ve got an online store. If users are always looking up the total order amount, you can store that sum right in the Orders table instead of recalculating it every time.

Just remember, denormalization is a trade-off. It ups the chances of errors when updating data.

Examples of a messy structure and how to normalize it

Let’s check out a table before normalization:

Order ID Client Products Order Total
1 Otto Lin Phone, Headphones 20000
2 Anna Song Fridge 30000
3 Otto Lin TV 40000

You can clearly see the issues here:

  • Client data is repeated.
  • Products are stored as a list—this breaks the rule of atomic data.

After normalization

We’ll split this table into three: Table Clients

Client ID Name
1 Otto Lin
2 Anna Song

Table Products

Product ID Name Price
1 Phone 10000
2 Headphones 10000
3 Fridge 30000
4 TV 40000

Table Orders

Order ID Client ID Product ID
1 1 1
1 1 2
2 2 3
3 1 4

Now we’ve got:

  • No duplicate data.
  • Each product is in its own row.
  • It’s easy to add new products and orders.

Normalization is the art of making order out of chaos. Yeah, sometimes it can feel a bit strict and demanding, but the end goal is totally worth it. In the next lectures, we’ll go through the normal forms one by one: first 1NF, then 2NF, and finally 3NF. Let’s go, to the world of organized data!

2
Task
SQL SELF, level 25, lesson 0
Locked
Working with real tables
Working with real tables
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION