View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
  1. Home
DBMS

DBMS Tutorial: Learn Database Management Basics

Learn the fundamentals of Database Management Systems (DBMS) with our comprehensive tutorial. Understand key concepts and practical applications. Start now!

  • 32
  • 8 Hours
right-top-arrow
7

3rd Normal Form (3NF)

Updated on 01/08/2024383 Views

Data has slowly become the backbone of every organization. Companies, governments, and individuals utilize databases to store and manage huge volumes of data. Databases therefore need to be well-designed to guarantee that information shared remains accurate, reliable, and easy to analyze. This is where database normalization comes into the picture.

Database normalization is a systematized way of arranging data in relational databases. It involves designing data tables to avoid repetition and helps improve data quality. The facility of redundancy can be referred to as the same data being stored in multiple places within a database. This results in a lack of congruence leads to mistakes, and is generally ineffective.

Data normalization helps to normalize using sets of rules called normal forms. These forms are data organization levels and each subsequent form is built upon the previous one. There are several normal forms, but the ones most commonly used are the 1st Normal Form (1NF), 2nd Normal Form (2NF), and 3rd Normal Form (3NF) in DBMS.

Understanding 3NF

Formally, a database table is in 3rd normal form in DBMS, if it satisfies the following conditions:

  • The table is at 2NF at least.
  • No attribute of the secondary key has any transitive dependencies with the primary key. The transitive dependency is where a non-prime attribute relies on another non-prime attribute, dependent on the primary key. This can cause data integrity problems.

Third normal form in DBMS with an example

Student

Name

Course

Result

24

Aarti Kumar

BCom

Passed

25

Sachin Sharma

BCom

Awaited

26

Karthik Kapoor

BSc

Awaited

27

Archana Rana

BBA

Passed

28

Anubhav Sinha

BCom

Passed

29

Riya Singh

BSc

Awaited

Here, “Course ID” is the foreign key, and “Student ID” is the primary key. This makes Course ID and Student Name no longer functionally dependent on each other and thus, deletion anomalies do not occur.

Advantages of 3NF

Since the Third Normal Form (3NF) in DBMS provides the database design with several benefits, it is the central pillar for reliable data management.
Here's a closer look at some of the key advantages of 3NF.

Enhanced Data Integrity

3rd normal form in DBMS not only provides data that is the same as the real objects but also ensures that data reflects real-world entities.

Reduced Data Redundancy

3NF can delete the repetition of data within an entire database. To avoid transitive dependencies, data is split into tables which are decomposed and stored in a single location.

Simplified Data Manipulation and Querying

3NF provides a logical and ordered manner of data structuring. It allows ease of conducting queries, data updates, and other data manipulation tasks.

Improved Scalability and Maintainability

3NF is a method that allows for modular database design. When your data volumes grow or schema requirements change, tables in 3NF can be easily modified or extended without affecting the whole database structure.

Implementing 3NF in Practice

Here's a step-by-step guide to normalize a database table to 3NF:

1. Identify Functional Dependencies

The primary action is to learn the functional relationship between the attributes within your table. An FD (functional dependency) occurs when the value of attribute X leads to the knowledge of the value of attribute Y. In other words, if you know the value of X, you can always find the corresponding value of Y, and there won't be any doubts about it.
Example:
Visualize a table storing details of the students enrolled in the courses (StudentID, CourseID, CourseName, InstructorName). It is a functional dependency that StudentID and CourseID are interconnected. Hence, it implies that the student's ID is the main factor to be considered. It will identify which course is being attended by the student.

2. Find out the Candidate Keys and Primary Keys

The candidate key is a collection of minimal elements that only can be used to distinguish each line in a table. In the case of the current example, both StudentID and {StudentID, CourseID} can be candidate keys. The primary candidate key is StudentID with CourseID dependent on it since StudentID already determines CourseID.
Example:
The main key, which is selected from the candidate keys, acts as an identifier. It is usually suggested to pick a small candidate key for the sake of reducing the amount of data repetition. In this instance, StudentID is the preferred choice for the primary key.

3. Eliminate Partial Dependencies

It is necessary to verify that there are no non-transitive partial dependencies, which are not transitive to the primary key. There is a partial dependency when one attribute (A) is the determiner of another attribute (B) and not the whole primary key. The transitive dependency is when A causes B and B causes C.
Example:
Imagine that we add an 'InstructorEmail' attribute to our table to illustrate this example. If CourseID determines InstructorEmail (given the class you have, you know the teacher's email), a partial dependency is developed. This is a problem because the CourseID is not the super key. An error could appear when you want to update InstructorEmail for a specific course but not for other courses taught by the same instructor.

4. Decompose and Build New Relationships

To obtain 3NF, the table must be decomposed into tables of smaller sizes that remove partial dependency. So, this decomposition means that each attribute is reliant on the primary key and not on the partial one. This would lead to partial dependencies and, consequently, anomalies.
Example:
For this case, we can have different tables such as 'Courses' (CourseID, CourseName, InstructorID) and 'Enrollments' (StudentID, CourseID). The table 'Courses' would have the primary key of CourseID, and the table 'Enrollments' would have the composite primary key of {StudentID, CourseID}. This can be followed by making a foreign key relationship between the tables. The CourseID in the 'Enrollments' table would be the foreign key (CourseID) corresponding to the primary key (CourseID) in the 'Courses' table.

5. Practical Example: Library Management System

Visualize a library management system that will have a table with information about books (BookID, Title, Author, Genre, Category, BranchID) as its data. One can easily feel that this table is not that bad. Nevertheless, this is the case as it reveals a breach of 3NF.

Category is the factor that determines the number of branches. This leads to partial dependency as the category of book (e.g., fiction) does not inform you of the exact branch of the library where the book is located (fiction books could be in more than one branch).

To achieve 3NF, we can decompose the table:

  • Books table (BookID, Title, Author, Genre) with BookID as a foreign key.
  • BookCategories table with a composite primary key of {BookID, Category} (BookID, Category). This feature makes a book a member of several categories.
  • BranchInventory table (BranchID, BookID): {BranchID, BookID} is a composite primary key. This set up the link between different branches and the books they contain.

Significance of Taking into Account Performance Aspects while Implementing 3NF in Real Situations

One needs to examine 3NF as a means to avoid data redundancy and dependency on the performance implications of practical scenarios.

Here’s why:

1. Reduced Redundancy and Dependency:

3NF helps in removing data redundancy and dependency and also assures that each non-key attribute should depend on the primary key(s). It helps to remove unnecessary data and maintain consistency of data, which contributes to the data integrity that is required for the process of database operations to be reliable.

2. Increased Joins:

3NF commonly results in a more disjointed data structure, where the data that relate to each other is stored in different tables. This requires more frequent joins to retrieve information, which can slow down the performance of queries.

3. Denormalization for Speed:

In certain instances, denormalization (a method of including a limited amount of redundancy in data) is used to enhance query performance. In this case, it becomes necessary to create a calculated field in the table, even if it's technically unnecessary, to avoid complex joins.

Although 3NF is a key principle for data integrity and consistency, the performance implications of normalization decisions in practical database implementations must be considered. Finding the sweet spot between normalization and optimization of performance guarantees that databases preserve data integrity and provide quick and efficient query processing. This is the basis for scalable and reliable data management systems.

Relation between 3NF and Boyce-Codd Normal Form (BCNF)?

While 3NF and BCNF aim to lower data redundancy and inconsistencies, they work at different levels of normalization, providing different benefits to database management.

Here’s how they relate:

1. Understanding Third Normal Form (3NF):

The 3NF is an element of database normalization. It focuses on reducing the redundancy and dependency in the relational database. It is based on the principles of 1NF and 2NF. This means that non-key attributes fully functionally depend on the primary key instead of other non-key attributes.

2. The Essence of Boyce-Codd Normal Form (BCNF):

A more stringent form of normalization than 3NF is the BCNF. It deals with issues left over even in databases that have been normalized up to the 3NF. BCNF specifies that all determinants (attributes that make another attribute unique) must be candidate keys, thus, no trivial dependency between attributes is supported.

3. Relationship Between 3NF and BCNF:

Both 3NF and BCNF aim to reduce data redundancy and inconsistency, however, BCNF is stricter than 3NF. Any table in BCNF will have to be in 3NF. While not all tables that comply with 3NF might meet stringent BCNF conditions, it is not always the case that all tables that comply with the 3NF conditions will also comply with the BCNF conditions. With the knowledge of the connection between the 3NF and BCNF, database designers can make educated choices to guarantee the accuracy and efficiency of data in relational databases.

Wrapping Up

Learning the 3rd normal form in DBMS will enable you to create efficient and stable databases. By exploring functional dependencies, determining candidate keys, and excluding partial dependencies, you will have a soundly structured data backbone for your applications.
Remember, 3NF should be the basis of most database designs, as it ensures data integrity and enables efficient data management.

Frequently Asked Questions

1. How to make a 3NF table in SQL?
To create a table in Third Normal Form (3NF) in SQL, follow these steps:

  • Identify functional dependencies: Set out all the functional dependencies in the table.
  • Create separate tables for each dependency: For every non-prime attribute associated with another non-prime attribute, generate a separate table.
  • Establish relationships: Link the tables through foreign keys to identify the relationships.
  • Ensure no transitive dependencies: Perform the check to ensure that there are no transitive dependencies between non-prime attributes of any table.

2. What is the process of converting to 3NF?
To convert a database schema to 3NF, follow these steps:

  • Start with 1NF and 2NF Tables: Verify that all tables are in 1NF and 2NF
  • Identify transitive dependencies: The prime attribute dependency can be identified where a non-prime attribute relies on another attribute that is also non-prime.
  • Create separate tables: Contrive different tables for every set of correlated attributes that are transitive in a dependency.
  • Establish relationships: Establish relationships between the newly-created tables using foreign keys.
  • Ensure integrity: Data integrity can be enhanced by the use of referential integrity constraints and primary key constraints.

3. What is 1NF, 2NF, 3NF, 4NF, 5NF in DBMS?

  • First Normal Form (1NF): Makes sure that each column is made of atomic values, and that there are no groups that are repeated.
  • Second Normal Form (2NF): Eliminates the prevalence of partial dependencies.
  • Third Normal Form (3NF): Removes transitive dependencies from dependencies.
  • Fourth Normal Form (4NF): Addresses multi-valued dependencies.
  • Fifth Normal Form (5NF): Assemblies are bound together.
Get Free Career Counselling
form image
+91
*
By clicking, I accept theT&Cand
Privacy Policy
image
Join 10M+ Learners & Transform Your Career
Learn on a personalised AI-powered platform that offers best-in-class content, live sessions & mentorship from leading industry experts.
right-top-arrowleft-top-arrow

upGrad Learner Support

Talk to our experts. We’re available 24/7.

text

Indian Nationals

1800 210 2020

text

Foreign Nationals

+918045604032

Disclaimer

upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enrolling. .