2082 3

BIT202 ยท 2082 ยท 10 marks

Why is normalization required? Define 1NF, 2NF and 3NF with suitable examples.

Why is normalization required? Define 1NF, 2NF and 3NF with suitable examples.[10]

Database Management SystemChapter 5: Normalization and Database DesignNormalization purpose and need

Quick answer

Normalization is the process of organizing a relational database to reduce data redundancy and improve data integrity by decomposing large, poorly structured tables into smaller, well-structured ones.

Normalization: Need, 1NF, 2NF, and 3NF


Why is Normalization Required?

Problems Without Normalization (Anomalies)

Consider the following unnormalized table:

StudentIDStudentNameCourseIDCourseNameInstructorIDInstructorName
1RamC01DBMSI01Dr. Sharma
1RamC02OSI02Dr. Gupta
2SitaC01DBMSI01Dr. Sharma

1. Insertion Anomaly: A new course cannot be inserted unless at least one student is enrolled in it. The course data depends on student data being present.

2. Deletion Anomaly: If Student 2 (Sita) drops Course C01, the information about Dr. Sharma teaching DBMS is also lost.

3. Update Anomaly: If Dr. Sharma's name changes, it must be updated in every row where C01 appears. Missing even one row causes inconsistency.

Goals of Normalization

  • Eliminate redundant data
  • Ensure data dependencies make sense
  • Make the database easier to maintain
  • Reduce storage space

First Normal Form (1NF)

Definition

A relation is in 1NF if:

  • All attributes contain atomic (indivisible) values
  • There are no repeating groups or multi-valued attributes
  • Each column contains values of a single type
  • Each row is uniquely identifiable

Example

Violation of 1NF:

StudentIDStudentNameCourses
1RamDBMS, OS
2SitaDBMS

Here, the Courses column has multiple values -- this violates 1NF.

After converting to 1NF:

StudentIDStudentNameCourse
1RamDBMS
1RamOS
2SitaDBMS

Now every attribute is atomic. The table is in 1NF.


Second Normal Form (2NF)

Definition

A relation is in 2NF if:

  • It is already in 1NF
  • Every non-key attribute is fully functionally dependent on the entire primary key (no partial dependency)

Partial Dependency: A non-key attribute depends on only a part of a composite primary key.

Example

Consider the table (Primary Key = {StudentID, CourseID}):

StudentIDCourseIDStudentNameCourseNameGrade
1C01RamDBMSA
1C02RamOSB
2C01SitaDBMSA

Functional Dependencies:

  • {StudentID, CourseID} --> Grade (full dependency -- OK)
  • StudentID --> StudentName (partial dependency -- violates 2NF)
  • CourseID --> CourseName (partial dependency -- violates 2NF)

After converting to 2NF (decompose):

Student Table:

StudentIDStudentName
1Ram
2Sita

Course Table:

CourseIDCourseName
C01DBMS
C02OS

Enrollment Table:

StudentIDCourseIDGrade
1C01A
1C02B
2C01A

Now all non-key attributes are fully dependent on the whole primary key. The tables are in 2NF.


Third Normal Form (3NF)

Definition

A relation is in 3NF if:

  • It is already in 2NF
  • There is no transitive dependency -- no non-key attribute depends on another non-key attribute

Transitive Dependency: If A --> B and B --> C, then A --> C is a transitive dependency (C depends on A through B).

Example

Consider the table (Primary Key = StudentID):

StudentIDStudentNameDeptIDDeptName
1RamD01Computer
2SitaD02Physics
3HariD01Computer

Functional Dependencies:

  • StudentID --> DeptID (direct dependency -- OK)
  • DeptID --> DeptName (DeptName depends on DeptID, not on StudentID)
  • Therefore: StudentID --> DeptID --> DeptName (transitive dependency -- violates 3NF)

After converting to 3NF (decompose):

Student Table:

StudentIDStudentNameDeptID
1RamD01
2SitaD02
3HariD01

Department Table:

DeptIDDeptName
D01Computer
D02Physics

Now there is no transitive dependency. Both tables are in 3NF.


Summary Table

Normal FormCondition
1NFAll attributes are atomic; no repeating groups
2NF1NF + No partial dependency on composite primary key
3NF2NF + No transitive dependency; every non-key attribute depends on the key alone

Conclusion

Normalization is required because an unnormalized table stores the same fact in many rows, which wastes space and, more seriously, allows the copies to disagree. Removing repeating groups gives 1NF, removing partial dependency on part of a composite key gives 2NF, and removing transitive dependency through a non-key attribute gives 3NF. Each step replaces one table by two smaller tables joined on a key, so the insertion, deletion and update anomalies disappear while the original information can still be recovered by a join. Most practical database designs stop at 3NF (or BCNF), since further decomposition begins to cost more in join time than it saves in redundancy.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.