Skip to content
Her Tech Corner Her Tech Corner
  • Home
  • Learn Spring
    • Spring Frameworks
    • Java Core
  • Microservices
  • Cloud
  • My Journey
    • Machine Learning
    • Linux
    • Algorithm
    • Book Notes
  • Tools I use
Her Tech Corner
Her Tech Corner

Data Normalization Explained – 1NF, 2NF, 3NF, 4NF

Posted on July 31, 2023September 4, 2023 By Hoai Thu

Last updated on September 4th, 2023

As I strive to expand my skill set, along with algorithms, I am focusing on honing my expertise in databases. In this post, I am going to find out the concept of data normalization, exploring its process through an example.

In simple terms, data normalization is a set of rules and practices for dealing with the design of relational databases and the arrangement of data in database tables. There are several normal forms, each with a specific objective. Let’s go through each of them to understand the normalization process.

Suppose I have a simple customer_order containing sales records, as below:

customer_namecustomer_emailproduct_namequantitysupplier_namesupplier_phone
John Doejohn.doe@email.comProduct A, Product B2Supplier 1(555)123-4567, (555)987-6543
John Doejohn.doe@email.comProduct C1Supplier 2(555)222-3333
Alan Smithalan.smith@email.comProduct A3Supplier 1(555)123-4567, (555)987-6543

Here is a demonstration of the normalization process:

Table of Contents

Toggle
  • 1NF – First Normal Form
  • 2NF – Second Normal Form
  • 3NF – Third Normal Form
  • 4NF – Fourth Normal Form

1NF – First Normal Form

Objective: Ensure that each column contains atomic values (no repeating groups or multi-valued attributes) and has a primary key.

So based on the above objective, the productName should be separated multiple into different rows and add customer_id:

customer_idcustomer_namecustomer_emailproduct_namequantitysupplier_namesupplier_phone
1John Doejohn.doe@email.comProduct A1Supplier 1(555)123-4567, (555)987-6543
1John Doejohn.doe@email.comProduct B1Supplier 1(555)123-4567, (555)987-6543
1John Doejohn.doe@email.comProduct C1Supplier 2(555)222-3333
2Alan Smithalan.smith@email.comProduct A3Supplier 1(555)123-4567, (555)987-6543

Our table is now in 1NF because each column has atomic values, and there’s a primary key (customerId). However, the table has redundant customer, product, and supplier information.

2NF – Second Normal Form

Objective: Ensure that tables meet 1NF requirements and every non-primary key attribute is fully functionally dependent on the primary key. There are no partial dependencies.

So based on the above objective, the customer information, product information, and supplier information should be separated into different tables to reduce partial dependencies:

customer table

customer_idcustomer_namecustomer_email
1John Doejohn.doe@email.com
2Alan Smithalan.smith@email.com

product table

product_idproduct_namesupplier_namesupplier_phone
1Product ASupplier 1(555)123-4567, (555)987-6543
2Product BSupplier 1(555)123-4567, (555)987-6543
3Product CSupplier 2(555)222-3333

order table

order_idcustomer_idproduct_idquantity
1111
1121
2131
3213

The tables are now in 2NF, and there are no partial dependencies. In the customer table, non-key columns such as customer_name, customer_email are functionally dependent on customer_id. customer_idand product_id are foreign keys connecting the three tables – they depend on the primary keys of their respective tables (customer and product).

3NF – Third Normal Form

Objective: Tables meet 2NF requirements, and no non-key column is transitively dependent on another non-key column.

To achieve 3NF, remove any transitive dependencies that may exist in non-key columns. product and suppliers tables still have a transitive dependency because the supplier_name is a non-key column that depends on the product_id. I’ll separate the supplier information into a new supplier table:

After applying 3NF:

product table

product_idproduct_namesupplier_id
1Product A1
2Product B1
3Product C2

supplier table

supplier_idsupplier_namesupplier_phone
1Supplier 1(555)123-4567, (555)987-6543
2Supplier 2(555)222-3333

Now all the tables satisfy the requirements for the 3NF:

  • order table: Quantity non-key column is functionally dependent on the primary key, OrderID, with no transitive dependencies.
  • customer table: customer_name, customer_email are functionally dependent on customer_id and do not depend on other non-key columns.
  • product table: product_name and supplier_id columns are functionally dependent on product_id and don’t depend on other non-key columns

4NF – Fourth Normal Form

Objective: Tables meet 3NF requirements, and eliminate multi-valued dependencies.

Since each supplier can have multiple phone numbers, there is a multi-valued dependency in the supplier table. To achieve 4NF, we need to eliminate multi-valued dependencies by dividing the supplier table into two separate tables – Suppliers and SupplierPhoneNumbers:

Eliminate multi-valued dependencies by further dividing the supplier table into supplier and supplier_info tables:

supplier table

SupplierIDSupplierName
1Supplier 1
2Supplier 2

supplier_info table

SupplierIDSupplierPhone
1(555)123-4567
1(555)987-6543
2(555)222-3333

Our final normalized design contains the following tables, adhering to the 4NF:

customer table

CustomerIDCustomerNameCustomerEmail
1John Doejohn.doe@email.com
2Alan Smithalan.smith@email.com

product table

ProductIDProductNameSupplierID
1Product A1
2Product B1
3Product C2

supplier table

SupplierIDSupplierName
1Supplier 1
2Supplier 2

supplier_info table

SupplierIDSupplierPhone
1(555)123-4567
1(555)987-6543
2(555)222-3333

order table

OrderIDCustomerIDProductIDQuantity
1112
2122
3131
4213

With these tables, we achieve a 4NF normalized design that eliminates most data anomalies and redundancies while allowing data to be efficiently stored and queried for a customer order management system. This design ensures better data integrity, maintainability, and scalability for the entire database.

Related

Database Database

Post navigation

Previous post
Next post

Categories

  • Algorithm (2)
  • Cloud (1)
  • Database (1)
  • Java Core (1)
  • Learn Spring (1)
  • Machine Learning (1)
  • Microservices (4)
  • Spring Frameworks (6)
  • Tools I use (1)

Recent Posts

  • Leetcode challenges 2023-2024December 12, 2023
  • Docker Essentials: A Novice’s JourneyOctober 7, 2023
  • Spring Cloud Gateway as an OAuth2 ClientSeptember 25, 2023
  • An Introduction to Prompt Engineering with LLMsSeptember 18, 2023
  • A brief overview of API Gateway Pattern in MicroservicesSeptember 7, 2023

Tags

Algorithms AOP API Gateway Authorization Server Cloud Database Design Pattern Docker Java8 Jwt Leetcode LLMs Microservices Oauth2 Prompt Refactoring Spring

©2025 Her Tech Corner | WordPress Theme by SuperbThemes