What is Database Normalization?

May 26, 2021

Introduction

Database normalization is a method in relational database design which helps properly organize data tables. The process aims to create a system that faithfully represents information and relationships without data loss or redundancy.

This article explains database normalization and how to normalize a database through a hands-on example.

Database Normalization

What is Database Normalization?

Database normalization is a technique for creating database tables with suitable columns and keys by decomposing a large table into smaller logical units. The process also considers the demands of the environment in which the database resides.

Normalization is an iterative process. Commonly, normalizing a database occurs through a series of tests. Each subsequent step decomposes tables into more manageable information, making the overall database logical and easier to work with.

Why is Database Normalization Important?

Normalization helps a database designer optimally distribute attributes into tables. The technique eliminates the following:

  • Attributes with multiple values.
  • Doubled or repeated attributes.
  • Non-descriptive attributes.
  • Attributes with redundant information.
  • Attributes created from other features.

Although total database normalization is not necessary, it provides a well-functioning information environment. The method systematically ensures:

  • A database structure suitable for generalized queries.
  • Minimized data redundancy, increasing memory efficiency on a database server.
  • Maximized data integrity through the reduced insert, update, and delete anomalies.

Database normalization transforms overall database consistency, providing an efficient environment.

Database Redundancies and Anomalies

When altering an entity in a table with redundancies, you must modify all repeated instances of information, and any other information related to the changed data. Othrewise, the database becomes inconsistent and anomalies happen when making changes.

For example, in the following unnormalized table:

Database anomalies example table

The table contains data redundancy, which in turn causes three anomalies when making data changes:

1. Insert anomaly. When trying to insert a new employee in the finance sector, you must also know the manager's name. Otherwise, you cannot insert data into the table.

2. Update anomaly. If an employee switches sectors, the manager's name ends up being incorrect. For example, if Jacob changes to finance, Adam stays as his manager.

3. Delete anomaly. If Joshua decides to leave the company, deleting the row also removes the information that a finance sector exists.

The solution to these anomalies is in database normalization concepts and steps.

Database Normalization Concepts

The elementary concepts used in database normalization are:

  • Keys. Column attributes that identify a database record uniquely.
  • Functional Dependencies. Constraints between two attributes in a relation.
  • Normal Forms. Steps to accomplish a certain quality of a database.

Database Normal Forms

Normalizing a database is achieved through a set of rules known as normal forms. The central concept is to help a database designer achieve the desired quality of a relational database.

Normal forms diagram

All levels of normalization are cumulative. Previous normal form requirements must be satisfied before moving on to the following form.

The stages of normalization are:

StageRedundancy Anomalies Addressed
Unnormalized Form (UNF)The state before any normalization. Redundant and complex values are present.
First Normal Form (1NF)Repeating and complex values split up, making all instances atomic.
Second Normal Form (2NF)Partial dependencies decompose to new tables. All rows functionally depend on the primary key.
Third Normal Form (3NF)Transitive dependencies decompose to new tables. Non-key attributes depend on the primary key.
Boyce-Codd Normal Form (BCNF)Transitive and partial functional dependencies for all candidate keys decompose to new tables.
Fourth Normal Form (4NF)Removal of multivalued dependencies.
Fifth Normal Form (5NF)Removal of JOIN dependencies.

A database is normalized when it fulfills the third normal form. Further steps in normalization make the database design complicated and could compromise the functionality of the system.

What is a KEY?

A database key is an attribute or a group of features that uniquely describes an entity in a table. The types of keys used in normalization are:

  • Super Key. A set of features that uniquely define each record in a table.
  • Candidate Key. Keys selected from the set of super keys where the number of fields is minimal.
  • Primary Key. The most appropriate choice from the set of candidate keys serves as the table's primary key.
  • Foreign Key. The primary key of another table.
  • Composite Key. Two or more attributes together form a unique key but are not keys individually.

As tables decompose into multiple simpler tables, keys define a point of reference for a database entity.

For example, in the following database structure:

Database keys example table

Some examples of super keys in the table are:

  • employeeID
  • (employeeID, name)
  • email

All super keys can serve as a unique identifier for each row. On the other hand, the employee's name or age are not unique identifiers because two people could have the same name or age.

The candidate keys come from the set of super keys where the number of fields is minimal. The choice comes down to two options:

  • employeeID
  • email

Both options contain a minimal number of fields, making them optimal candidate keys. The most logical choice for the primary key is the employeeID because an employee's email can change. The primary key in the table is easy to reference as a foreign key in another table.

Functional Database Dependencies

A functional database dependency represents a relationship between two attributes in a database table. Some types of functional dependencies are:

  • Trivial Functional Dependency. A dependency between an attribute and a group of features where the original element is in the group.
  • Non-Trivial Functional Dependency. A dependency between an attribute and a group where the feature is not in the group.
  • Transitive Dependency. A functional dependency between three attributes where the second depends on the first and the third depends on the second. Due to transitivity, the third attribute is dependent on the first.
  • Multivalued Dependency. A dependency where multiple values depend on one attribute.

Functional dependencies are an essential step in database normalization. In the long run, the dependencies help determine the overall quality of a database.

Database Normalization Example - How to Normalize a Database?

The general steps in database normalization work for every database. The specific steps of dividing the table as well as whether to go past 3NF depend on the use case.

Example Unnormalized Database

An unnormalized table has multiple values within a single field, as well as redundant information in the worst case.

For example:

managerIDmanagerNameareaemployeeIDemployeeNamesectorIDsectorName
1Adam A.East1
2
David D.
Eugene E.
4
3
Finance
IT
2Betty B.West3
4
5
George G.
Henry H.
Ingrid I.
2
1
4
Security
Administration
Finance
3Carl C.North6
7
James J.
Katy K.
1
4
Administration
Finance

Inserting, updating, and removing data is a complex task. Performing any alterations to the existing table has a high risk of losing information.

Step 1: First Normal Form 1NF

To rework the database table into the 1NF, values within a single field must be atomic. All complex entities in the table divide into new rows or columns.

The information in the columns managerID, managerName, and area repeat for each employee to ensure no loss of information.  

managerIDmanagerNameareaemployeeIDemployeeNamesectorIDsectorName
1Adam A.East1David D.4Finance
1Adam A.East2Eugene E.3IT
2Betty B.West3George G.2Security
2Betty B.West4Henry H.1Administration
2Betty B.West5Ingrid I.4Finance
3Carl C.North6James J.1Administration
3Carl C.North7Katy K.4Finance

The reworked table satisfies the first normal form.

Step 2: Second Normal Form 2NF

The second normal form in database normalization states that each row in the database table must depend on the primary key.

The table splits into two tables to satisfy the normal form:

  • Manager (managerID, managerName, area)
managerIDmanagerNamearea
1Adam A.East
2Betty B.West
3Carl C.North
  • Employee (employeeID, employeeName, managerID, sectorID, sectorName)
employeeIDemployeeNamemanagerIDsectorIDsectorName
1David D.14Finance
2Eugene E.13IT
3George G.22Security
4Henry H.21Administration
5Ingrid I.24Finance
6James J.31Administration
7Katy K.34Finance

The resulting database in the second normal form is currently two tables with no partial dependencies.

Step 3: Third Normal Form 3NF

The third normal form decomposes any transitive functional dependencies. Currently, the table Employee has a transitive dependency which decomposes into two new tables:

  • Employee (employeeID, employeeName, managerID, sectorID)
employeeIDemployeeNamemanagerIDsectorID
1David D.14
2Eugene E.13
3George G.22
4Henry H.21
5Ingrid I.24
6James J.31
7Katy K.34
  • Sector (sectorID, sectorName)
sectorIDsectorName
1Administration
2Security
3IT
4Finance

The database is currently in third normal form with three relations in total. The final structure is:

normalized database example

At this point, the database is normalized. Any further normalization steps depend on the use case of the data.

Conclusion

The article showed that database normalization is a method in which a database reduces the amount of redundant information. In the long run, the process helps minimize data loss as well as improve the overall organization.

Database denormalization is a technique used to improve data access performances. Learn more about what database denormalization is and the different techniques used to speed up a database.

If a database is hard to normalize, consider migrating the database to another database type.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is an aspiring technical writer at phoenixNAP and a data nerd. Her background in Electrical Engineering and Computing and her teaching experience give her a unique set of skills - being able to easily explain complex technical concepts through her content.
Next you should read
How To Use MySQL JOINS {With Examples}
April 20, 2021

JOINS in MySQL are used to combine information located in multiple tables and retrieve that...
Read more
MySQL Commands Cheat Sheet
January 20, 2021

Need a reference sheet for all the important MySQL commands? Check out this MySQL Commands article which…
Read more
Data Warehouse Architecture Explained
October 29, 2020

A data warehouse is a complex system that stores historical and cumulative data used for forecasting...
Read more
What is a Document Database?
May 13, 2021

With unique capabilities, NoSQL databases overcome the constraints found in the relational database model. NoSQL...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.