BIT202 ยท 2080 ยท 5 marks
What is Normalization? Explain the 2NF with Examples.
What is Normalization? Explain the 2NF with Examples. [5]
Quick answer
Normalization is the process of organizing the attributes and tables of a relational database to minimize data redundancy and improve data integrity. It involves decomposing a large table into smaller, well-structured tables and defining relationships between them.
Normalization and Second Normal Form (2NF)
What is Normalization?
Goals of Normalization:
- Eliminate redundant data
- Ensure data dependencies make sense
- Reduce anomalies (insertion, update, deletion anomalies)
Second Normal Form (2NF)
A relation is in Second Normal Form (2NF) if:
- It is already in First Normal Form (1NF), AND
- Every non-key attribute is fully functionally dependent on the entire primary key (i.e., there is no partial dependency).
Partial Dependency: A non-key attribute depends on only a part of a composite primary key, not the whole key.
Note: 2NF is only relevant when the primary key is composite (made up of more than one attribute).
Example
Table NOT in 2NF
Consider the following relation:
| StudentID | CourseID | StudentName | CourseName | Grade |
|---|---|---|---|---|
| S01 | C01 | Ram | DBMS | A |
| S01 | C02 | Ram | OS | B |
| S02 | C01 | Sita | DBMS | A+ |
- Primary Key: (StudentID, CourseID) -- composite key
- Functional Dependencies:
- (StudentID, CourseID) โ Grade โ (full dependency)
- StudentID โ StudentName โ (partial dependency)
- CourseID โ CourseName โ (partial dependency)
StudentName depends only on StudentID, and CourseName depends only on CourseID. These are partial dependencies, so this table violates 2NF.
Converting to 2NF
Decompose the table to remove partial dependencies:
Table 1: Student
| StudentID | StudentName |
|---|---|
| S01 | Ram |
| S02 | Sita |
Table 2: Course
| CourseID | CourseName |
|---|---|
| C01 | DBMS |
| C02 | OS |
Table 3: Enrollment
| StudentID | CourseID | Grade |
|---|---|---|
| S01 | C01 | A |
| S01 | C02 | B |
| S02 | C01 | A+ |
Now:
- Each non-key attribute is fully dependent on the whole primary key.
- All three tables are in 2NF.
Summary
| Normal Form | Condition |
|---|---|
| 1NF | Atomic values, no repeating groups |
| 2NF | 1NF + No partial dependency on composite key |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.