Normalize a Table up to Third Normal Form (3NF)

Problem: Normalize a Table up to Third Normal Form (3NF)

Suppose we have the following unnormalized table in a university database:

Student_Course_Record (Unnormalized Form)

StudentIDStudentNameDepartmentCourseIDsCourseNamesInstructorNames
101AhsanCSEC101, C102DBMS, AlgorithmsRahman, Karim
102NabilaCSEC101DBMSRahman
103TanvirEEEE201, E202Circuits, ElectronicsAhmed, Hasan

Problems in This Table

  • Multiple courses are stored in a single row (repeating groups).

  • Course details are mixed with student details.

  • Instructor depends on Course, not directly on Student.

Now, normalize this table step by step up to Third Normal Form (3NF).


Step 1: First Normal Form (1NF)

Rule of 1NF:

  • Remove repeating groups.

  • Ensure each column contains atomic (single) values.

  • Each row must be unique.

Transformed Table (1NF)

StudentIDStudentNameDepartmentCourseIDCourseNameInstructorName
101AhsanCSEC101DBMSRahman
101AhsanCSEC102AlgorithmsKarim
102NabilaCSEC101DBMSRahman
103TanvirEEEE201CircuitsAhmed
103TanvirEEEE202ElectronicsHasan

Justification:

  • Repeating groups (multiple courses in one cell) are removed.

  • Each field now contains only one value.

  • Table structure is atomic.

However, problems still exist:

  • StudentName and Department depend only on StudentID.

  • CourseName and InstructorName depend only on CourseID.

  • This creates partial dependency.


Step 2: Second Normal Form (2NF)

Rule of 2NF:

  • Must already be in 1NF.

  • Remove partial dependencies.

  • Non-key attributes must depend on the entire primary key.

Here, the composite key is:
(StudentID, CourseID)

But:

  • StudentName, Department depend only on StudentID.

  • CourseName, InstructorName depend only on CourseID.

Transformed Tables (2NF)

1. Students Table

StudentIDStudentNameDepartment
101AhsanCSE
102NabilaCSE
103TanvirEEE

2. Courses Table

CourseIDCourseNameInstructorName
C101DBMSRahman
C102AlgorithmsKarim
E201CircuitsAhmed
E202ElectronicsHasan

3. Enrollments Table

StudentIDCourseID
101C101
101C102
102C101
103E201
103E202

Justification:

  • Student-related data stored separately.

  • Course-related data stored separately.

  • Enrollment table connects students and courses.

  • Partial dependencies removed.

But still:

  • InstructorName may depend on CourseName.

  • Department details may depend on another attribute.

  • This creates transitive dependency.


Step 3: Third Normal Form (3NF)

Rule of 3NF:

  • Must already be in 2NF.

  • Remove transitive dependencies.

  • Non-key attributes should depend only on the primary key.

Assume:

  • Each Instructor teaches one Course.

  • Each Department has a DepartmentHead.

If Instructor details are separate, we refine further.

Final Tables (3NF)

1. Students

StudentIDStudentNameDepartmentID
101AhsanD01
102NabilaD01
103TanvirD02

2. Departments

DepartmentIDDepartmentName
D01CSE
D02EEE

3. Courses

CourseIDCourseName
C101DBMS
C102Algorithms
E201Circuits
E202Electronics

4. Instructors

InstructorIDInstructorNameCourseID
I01RahmanC101
I02KarimC102
I03AhmedE201
I04HasanE202

5. Enrollments

StudentIDCourseID
101C101
101C102
102C101
103E201
103E202

Justification:

  • Transitive dependencies removed.

  • Student depends only on StudentID.

  • Course depends only on CourseID.

  • Department stored separately.

  • Instructor stored separately.

  • Data redundancy minimized.

  • Update, insertion, and deletion anomalies eliminated.


Final Summary

Normal FormProblem Removed
1NFRepeating groups
2NFPartial dependency
3NFTransitive dependency

Now the database is fully normalized up to Third Normal Form (3NF), ensuring:

  • Minimal redundancy

  • Better data integrity

  • No update anomalies

  • Improved consistency


কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন