Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF

Introduction to Database Normalization

Overview: This video provides an introduction to database normalization, exploring the concept from a practical perspective. It covers the so-called normal forms from First Normal Form all the way up to Fifth Normal Form, and explains what we gain by doing normalization, and what we lose by failing to do it.

What is Normalization?

  • Normalization is the process of structuring a database table in such a way that it can't express redundant information.
  • Normalized database tables are not only protected from contradictory data, they're also easier to understand, easier to enhance and extend, and protected from insertion anomalies, update anomalies, and deletion anomalies.

Assessing Normalization Levels

  • To determine if a table isn't normalized enough, there are sets of criteria we can use to assess the level of danger. These sets of criteria have names like “first normal form”, “second normal form”, “third normal form”, and so on.
  • Think of these normal forms by analogy to safety assessments. If a table meets the requirements of first normal form, that's a bare minimum safety guarantee. If it meets the requirements of second normal form, that's an even greater safety guarantee. And so on.

First Normal Form

  • First Normal Form is violated when a list conveys meaning through the order of its elements. For example, a list titled “Members Of The Beatles From Tallest To Shortest” conveys meaning through the order of the names.
  • Lists like this are totally comprehensible to us, but they're not normalized. Remember, there's no such thing as row order within a relational database table.

Understanding First Normal Form

Overview: This section covers the four ways in which a design can fail to achieve First Normal Form, and how to design a table that respects First Normal Form.

Violating First Normal Form

  • Using row order to convey information is not permitted.
  • Mixing data types within the same column is not permitted.
  • Having a table without a primary key is not permitted.
  • Repeating groups are not permitted.

Designing a Table That Respects First Normal Form

  • Designate a primary key for the table.
  • Ensure that each column contains only one data type.
  • Avoid storing repeating groups of data items on a single row.

Understanding Second Normal Form

Overview: This section covers how to enhance a table that is already in First Normal Form to achieve Second Normal Form.

Enhancing a Table to Achieve Second Normal Form

  • Record the current rating of each player.
  • Ensure that all non-key columns depend on the entire primary key.

Deletion Anomaly

Overview: This section discusses the concept of a deletion anomaly in relation to a database table design.

What is a Deletion Anomaly?

  • A deletion anomaly occurs when a row is deleted from a database table, resulting in the loss of important information that cannot be recovered.
  • In the example given, if player gila19 loses all her copper coins, leaving her with nothing in her inventory, the single entry that she did have in the Player_Inventory table is now gone. If we try to query the database to find out what gila19’s Player Rating is, we’re out of luck.

Update Anomaly

Overview: This section discusses the concept of an update anomaly in relation to a database table design.

What is an Update Anomaly?

  • An update anomaly occurs when an update to a database table goes wrong, resulting in logical inconsistencies.
  • In the example given, if player jdog21 improves his rating from Intermediate to Advanced, and only one of jdog21’s records gets updated, the other record gets left alone. As far as the database is concerned, jdog21 is somehow both Intermediate and Advanced at the same time.

Insertion Anomaly

Overview: This section discusses the concept of an insertion anomaly in relation to a database table design.

What is an Insertion Anomaly?

  • An insertion anomaly occurs when a new row is added to a database table, but the data cannot be recorded due to the structure of the table.
  • In the example given, if a new player called tina42 comes along, who is a Beginner and has nothing in her inventory yet, we want to record the fact that she’s a Beginner, but because she has nothing in her inventory, we can’t insert a tina42 row into the Player_Inventory table. So her rating goes unrecorded.

Second Normal Form

Overview: This section discusses the concept of Second Normal Form in relation to a database table design.

What is Second Normal Form?

  • Second Normal Form is about how a table’s non-key columns relate to the primary key.
  • Informally, Second Normal Form states that each non-key attribute in the table must be dependent on the entire primary key.
  • In the example given, Player_Rating does not depend on the entire primary key, as it is a property of the Player only. This dependency on Player is the problem, as Player is part of the primary key, but not the whole key.

Understanding Third Normal Form

Overview: This section covers the concept of Third Normal Form, which is the culmination of database normalization. It explains how to identify and repair a design that is not in Third Normal Form, and introduces Boyce-Codd Normal Form as a slightly stronger flavor of Third Normal Form.

What is Third Normal Form?

  • Third Normal Form is the culmination of database normalization.
  • It states that every non-key attribute in a table should depend on the key, the whole key, and nothing but the key.
  • A transitive dependency occurs when an attribute depends on another non-key attribute. This is not allowed in Third Normal Form.

How to Repair a Design Not in Third Normal Form

  • To repair a design not in Third Normal Form, remove the non-key attribute from the table and introduce a new table that tells us everything we need to know about how to translate the attribute.

Boyce-Codd Normal Form

  • Boyce-Codd Normal Form is a slightly stronger flavor of Third Normal Form.
  • It can be summarized as "every attribute in a table should depend on the key, the whole key, and nothing but the key."
  • In almost all cases, once you’ve normalized a table this far, you’ve fully normalized it.

Fourth and Fifth Normal Form

  • Fourth and Fifth Normal Form are used in rare instances where Third Normal Form isn't enough.
  • An example of this is given with the website DesignMyBirdhouse.com.

Representing Data in Third Normal Form

Overview: This section covers the concept of Third Normal Form and how it can be used to represent data. It also discusses the problems that can arise when using this form, and how to fix them.

Multivalued Dependencies

  • A single table can be used to represent all possible combinations of data.
  • The primary key consists of all three columns: Model, Color, Style.
  • Problems can arise if a specific Model isn’t associated with just one Color.
  • To express this relationship, each Model has a specific set of available Colors, which is called a multivalued dependency.
  • Fourth Normal Form states that the only kinds of multivalued dependency allowed in a table are multivalued dependencies on the key.

Fixing the Problem

  • To fix the problem, the table must be split into multiple tables.
  • This will ensure that no anomalies are possible.

Fifth Normal Form

Overview: This section covers the concept of Fifth Normal Form and how it can be used to represent data. It also discusses the problems that can arise when using this form, and how to fix them.

Example

  • Three different brands of ice cream are available: Frosty’s, Alpine, and Ice Queen.
  • Each of the three brands of ice cream offers a different range of flavors.
  • Jason and Suzy have different preferences for the types of ice cream they like.
  • This information can be expressed in a table.

Problem

  • If tastes change, the table must be updated.
  • If done incorrectly, this can lead to logically inconsistent results.

Solution

  • To avoid this problem, the three pieces of information should be represented in three separate tables.
  • This will ensure that all facts of the situation are represented accurately.

First Normal Form

Overview: This section covers the rules for First Normal Form, which is the first step in normalizing a database.

Rules:

  • Using row order to convey information is not permitted
  • Mixing data types within the same column is not permitted
  • Having a table without a primary key is not permitted
  • Repeating groups are not permitted

Second Normal Form

Overview: This section covers the rule for Second Normal Form, which states that each non-key attribute in the table must be dependent on the entire primary key.

Third Normal Form

Overview: This section covers the rule for Third Normal Form, which states that each non-key attribute in a table must depend on the key, the whole key, and nothing but the key.

Fourth Normal Form

Overview: This section covers the rule for Fourth Normal Form, which states that the only kinds of multivalued dependency we’re allowed to have in a table are multivalued dependencies on the key.

Fifth Normal Form

Overview: This section covers the rule for Fifth Normal Form, which states that it must not be possible to describe the table as being the logical result of joining some other tables together.

Turn any video into a summary like this

YouTube links, meetings, lectures. With transcripts, search, and chat.

Video description

Want to go deeper? I wrote a comprehensive e-book that covers everything in this video — plus more step-by-step detail, BCNF/4NF/5NF in depth, exercises and solutions. 📘 Get the complete guide → https://decomplexify.org/e-dbnorm ───────────────────────────── IN THIS VIDEO This easy-to-follow database normalization tutorial makes use of lots of examples and focuses on the design process. It explains the "why" and "how" of normalization, and takes you step-by-step through: • First Normal Form (1NF) • Second Normal Form (2NF) • Third Normal Form (3NF), with a side note on Boyce-Codd Normal Form (BCNF) • Fourth Normal Form (4NF) • Fifth Normal Form (5NF) ───────────────────────────── WANT MORE? My guidebook, DATABASE NORMALIZATION MADE SIMPLE, takes everything here further: ✔ In-depth, step-by-step explorations of the normal forms starting with 1NF and its nuances (atomicity, etc) ✔ Exercises and solutions at the end of each normal form section ✔ Boyce-Codd Normal Form and why it is in some sense the most important normal form of all ✔ Extensively reworked and expanded material on 4NF and 5NF, projections and join dependencies ✔ 🎁 BONUS included with the guidebook: Interactive SQL facility featuring tables with normalization issues 📘 DATABASE NORMALIZATION MADE SIMPLE → https://decomplexify.org/e-dbnorm ───────────────────────────── Video Timeline: 0:00 What is database normalization? 3:55 First Normal Form (1NF) 10:24 Second Normal Form (2NF) 16:08 Third Normal Form (3NF) 20:29 Fourth Normal Form (4NF) 23:47 Fifth Normal Form (5NF) 26:41 Summary and review Corrections can be found in the pinned comment. 👉 You can also download a FREE PDF (Decomplexify Quick Reference Guide), with cheat sheets covering 1st, 2nd, and 3rd Normal Form, plus Entity Relationship Diagram (ERD) conventions: https://decomplexify.myflodesk.com/wm7ixaj2x6