2080 2

CSC265 ยท 2080 ยท 10 marks

Define normalization. Why normalization is important in database design? Explain 1NF, 2NF and 3NF with suitable example.

Define normalization. Why normalization is important in database design? Explain 1NF, 2NF and 3NF with suitable example.[10]

Database Management SystemChapter 7: Relational Database DesignNormal Forms Based on Primary Keys

Quick answer

Normalization is the process of organizing the attributes and tables of a relational database to minimize data redundancy and dependency. It involves decomposing a large, poorly structured table into smaller, well-structured tables while preserving data integrity and relationships. The process is guided by a series of rules called Normal Forms (NF).

Normalization in Database Design

Definition of Normalization


Why Normalization is Important in Database Design

Normalization is important for the following reasons:

ReasonExplanation
Eliminates RedundancyAvoids storing the same data in multiple places, saving storage space
Prevents Update AnomaliesEnsures that updating one record does not require updating many records
Prevents Insertion AnomaliesAllows inserting data without requiring unrelated data to be present
Prevents Deletion AnomaliesPrevents accidental loss of useful data when deleting a record
Improves Data IntegrityMaintains consistency and accuracy of data across the database
Simplifies QueriesWell-structured tables make querying easier and more efficient

Types of Anomalies (Before Normalization)

Consider the following unnormalized table:

StudentIDStudentNameCourseIDCourseNameInstructorName
1RamC01DBMSDr. Sharma
1RamC02OSDr. Thapa
2SitaC01DBMSDr. Sharma
  • Update Anomaly: If Dr. Sharma's name changes, it must be updated in multiple rows.
  • Insertion Anomaly: A new course cannot be added without a student.
  • Deletion Anomaly: Deleting Sita's record also deletes information about Course C01.

Normal Forms

1. First Normal Form (1NF)

Definition: A relation is in 1NF if:

  • All attributes contain only atomic (indivisible) values.
  • Each column contains values of a single type.
  • Each row is unique (has a primary key).
  • There are no repeating groups or multi-valued attributes.

Example of a table NOT in 1NF:

StudentIDStudentNameCourses
1RamDBMS, OS
2SitaDBMS

Here, the Courses column contains multiple values, which violates 1NF.

Converting to 1NF:

StudentIDStudentNameCourse
1RamDBMS
1RamOS
2SitaDBMS

Now each cell has an atomic value. This table is in 1NF. Primary Key: (StudentID, Course)


2. 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 of a table in 1NF but NOT in 2NF:

StudentIDCourseStudentNameInstructorName
1DBMSRamDr. Sharma
1OSRamDr. Thapa
2DBMSSitaDr. Sharma

Primary Key: (StudentID, Course)

Functional Dependencies:

  • (StudentID, Course) --> InstructorName (full dependency - OK)
  • StudentID --> StudentName (partial dependency - VIOLATION)

StudentName depends only on StudentID, not on the full composite key.

Converting to 2NF (Remove partial dependencies):

Student Table:

StudentIDStudentName
1Ram
2Sita

Enrollment Table:

StudentIDCourseInstructorName
1DBMSDr. Sharma
1OSDr. Thapa
2DBMSDr. Sharma

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


3. Third Normal Form (3NF)

Definition: A relation is in 3NF if:

  • It is already in 2NF.
  • There is no transitive dependency of non-key attributes on the primary key.

Transitive Dependency: A non-key attribute depends on another non-key attribute, which in turn depends on the primary key. If A --> B and B --> C, then A --> C is a transitive dependency.

Example of a table in 2NF but NOT in 3NF:

StudentIDCourseInstructorIDInstructorName
1DBMSI01Dr. Sharma
1OSI02Dr. Thapa
2DBMSI01Dr. Sharma

Primary Key: (StudentID, Course)

Functional Dependencies:

  • (StudentID, Course) --> InstructorID (full dependency - OK)
  • InstructorID --> InstructorName (transitive dependency - VIOLATION)

Here: (StudentID, Course) --> InstructorID --> InstructorName

InstructorName depends on InstructorID (a non-key attribute), not directly on the primary key.

Converting to 3NF (Remove transitive dependencies):

Enrollment Table:

StudentIDCourseInstructorID
1DBMSI01
1OSI02
2DBMSI01

Instructor Table:

InstructorIDInstructorName
I01Dr. Sharma
I02Dr. Thapa

The transitive dependency is now gone. InstructorName is stored exactly once, in the table whose key it actually depends on, while the Enrollment table keeps only InstructorID as a foreign key. Both tables are in 3NF, and the original information can be recovered without loss by joining them on InstructorID.

The anomalies listed at the beginning disappear with it. Correcting Dr. Sharma's name now changes a single row of the Instructor table, so there is no update anomaly. A new instructor can be recorded before any student enrols under that instructor, so there is no insertion anomaly. Deleting the last enrolment for a course no longer erases the instructor's details, so there is no deletion anomaly.


Summary of the Three Normal Forms

Normal FormRequirementProblem Removed
1NFAll attribute values atomic, no repeating groupsMulti valued cells that cannot be queried or indexed
2NFIn 1NF and every non key attribute fully dependent on the whole primary keyRedundancy caused by partial dependency on part of a composite key
3NFIn 2NF and no transitive dependency on the primary keyRedundancy caused by one non key attribute determining another

Normalization therefore moves a design from a single wide table full of repeated facts towards a set of narrow tables in which every fact is stored once and depends on the key, the whole key and nothing but the key. Stricter forms such as BCNF and 4NF handle the remaining special cases, but 3NF is normally sufficient for practical database design, and a controlled amount of denormalization is added afterwards only where read performance demands it.

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