CSC326 ยท 2081 ยท 5 marks
List the advantages of Normalization. Explain 2NF with an example.
List the advantages of Normalization. Explain 2NF with an example. [5]
Quick answer
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. Its key advantages are: Eliminates Data Redundancy; Prevents Update Anomalies; Prevents Insertion Anomalies.
Advantages of Normalization and Explanation of 2NF
Advantages of Normalization
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. Its key advantages are:
- Eliminates Data Redundancy: Removes duplicate data stored across multiple tables, saving storage space.
- Prevents Update Anomalies: Ensures that updating a single fact requires changing it in only one place.
- Prevents Insertion Anomalies: Allows new data to be inserted without requiring unrelated data to be present.
- Prevents Deletion Anomalies: Ensures that deleting a record does not unintentionally remove other important data.
- Improves Data Integrity and Consistency: Data remains accurate and consistent throughout the database.
- Easier Maintenance: A well-normalized database is easier to modify and extend.
Second Normal Form (2NF)
Definition
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 on any part of a composite primary key).
Partial Dependency: A non-key attribute depends on only a part of the composite primary key, not the whole key.
Example
Consider the following relation with a composite primary key (StudentID, CourseID):
| StudentID | CourseID | StudentName | CourseName | Marks |
|---|---|---|---|---|
| S01 | C01 | Ram | DBMS | 75 |
| S01 | C02 | Ram | OS | 80 |
| S02 | C01 | Sita | DBMS | 70 |
Primary Key: (StudentID, CourseID)
Identifying Partial Dependencies:
StudentNamedepends only onStudentID(not on the full key) -- Partial DependencyCourseNamedepends only onCourseID(not on the full key) -- Partial DependencyMarksdepends on bothStudentIDandCourseID-- Full Dependency (OK)
Since partial dependencies exist, this relation is NOT in 2NF.
Converting to 2NF
We decompose the table to remove partial dependencies:
Table 1: Student (depends on StudentID)
| StudentID | StudentName |
|---|---|
| S01 | Ram |
| S02 | Sita |
Table 2: Course (depends on CourseID)
| CourseID | CourseName |
|---|---|
| C01 | DBMS |
| C02 | OS |
Table 3: Enrollment (depends on full composite key)
| StudentID | CourseID | Marks |
|---|---|---|
| S01 | C01 | 75 |
| S01 | C02 | 80 |
| S02 | C01 | 70 |
Now all non-key attributes are fully functionally dependent on the entire primary key in each table. The database is now in 2NF.
Note: 2NF is only relevant when the primary key is composite. If a relation has a single-attribute primary key and is in 1NF, it is automatically in 2NF.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.