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]
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:
| Reason | Explanation |
|---|---|
| Eliminates Redundancy | Avoids storing the same data in multiple places, saving storage space |
| Prevents Update Anomalies | Ensures that updating one record does not require updating many records |
| Prevents Insertion Anomalies | Allows inserting data without requiring unrelated data to be present |
| Prevents Deletion Anomalies | Prevents accidental loss of useful data when deleting a record |
| Improves Data Integrity | Maintains consistency and accuracy of data across the database |
| Simplifies Queries | Well-structured tables make querying easier and more efficient |
Types of Anomalies (Before Normalization)
Consider the following unnormalized table:
| StudentID | StudentName | CourseID | CourseName | InstructorName |
|---|---|---|---|---|
| 1 | Ram | C01 | DBMS | Dr. Sharma |
| 1 | Ram | C02 | OS | Dr. Thapa |
| 2 | Sita | C01 | DBMS | Dr. 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:
| StudentID | StudentName | Courses |
|---|---|---|
| 1 | Ram | DBMS, OS |
| 2 | Sita | DBMS |
Here, the Courses column contains multiple values, which violates 1NF.
Converting to 1NF:
| StudentID | StudentName | Course |
|---|---|---|
| 1 | Ram | DBMS |
| 1 | Ram | OS |
| 2 | Sita | DBMS |
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:
| StudentID | Course | StudentName | InstructorName |
|---|---|---|---|
| 1 | DBMS | Ram | Dr. Sharma |
| 1 | OS | Ram | Dr. Thapa |
| 2 | DBMS | Sita | Dr. 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:
| StudentID | StudentName |
|---|---|
| 1 | Ram |
| 2 | Sita |
Enrollment Table:
| StudentID | Course | InstructorName |
|---|---|---|
| 1 | DBMS | Dr. Sharma |
| 1 | OS | Dr. Thapa |
| 2 | DBMS | Dr. 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:
| StudentID | Course | InstructorID | InstructorName |
|---|---|---|---|
| 1 | DBMS | I01 | Dr. Sharma |
| 1 | OS | I02 | Dr. Thapa |
| 2 | DBMS | I01 | Dr. 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:
| StudentID | Course | InstructorID |
|---|---|---|
| 1 | DBMS | I01 |
| 1 | OS | I02 |
| 2 | DBMS | I01 |
Instructor Table:
| InstructorID | InstructorName |
|---|---|
| I01 | Dr. Sharma |
| I02 | Dr. 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 Form | Requirement | Problem Removed |
|---|---|---|
| 1NF | All attribute values atomic, no repeating groups | Multi valued cells that cannot be queried or indexed |
| 2NF | In 1NF and every non key attribute fully dependent on the whole primary key | Redundancy caused by partial dependency on part of a composite key |
| 3NF | In 2NF and no transitive dependency on the primary key | Redundancy 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.