Normalization:
- Process of organizing a relational database to minimize redundancy and dependency.
- Aims to reduce anomalies in database operations like insertion, update, and deletion.
- Achieved by splitting table into multiple tables based on their logical relationship
- First Normal Form (1NF):
- A table is in 1NF if:
- All attributes contain atomic (indivisible) values.
- Each attribute contains only a single value (no sets or arrays).
- All records (rows) are unique.
- Example:
- A table with
StudentID,StudentName, andCourses(whereCoursescontains a list) violates 1NF. It should be split into separate rows for each course.
- A table with
- A table is in 1NF if:
- Second Normal Form (2NF):
- A table is in 2NF if:
- It is in 1NF.
- There is no partial dependency; non-prime attributes must be fully functionally dependent on the entire primary key, not just part of it.
- Applies to tables with composite keys (multiple attributes forming the primary key).
- Example:
- A
StudentCoursetable with{StudentID, CourseID}as a composite key may violate 2NF if theInstructorNamedepends only onCourseID. This should be moved to a separateCoursestable.
- A
- A table is in 2NF if:
- Third Normal Form (3NF):
- A table is in 3NF if:
- It is in 2NF.
- There are no transitive dependencies; non-prime attributes must not depend on other non-prime attributes.
- Eliminates redundancy caused by indirect dependencies.
- Example:
- A
Studenttable withStudentID,StudentName, andInstructorName, whereInstructorNamedepends onCourseID(which is in another table), violates 3NF.InstructorNameshould be moved to aCoursestable.
- A
- A table is in 3NF if:
- Boyce-Codd Normal Form (BCNF):
- A table is in BCNF if:
- It is in 3NF.
- For every non-trivial functional dependency, the determinant (attribute that determines others) must be a superkey.
- BCNF deals with situations where 3NF is satisfied but certain functional dependencies still exist that are not based on superkeys.
- Example:
- A table with
{StudentID, CourseID, InstructorName}where{InstructorName → CourseID}violates BCNF becauseInstructorNameis not a superkey. To satisfy BCNF,InstructorNameshould be removed to a separate table.
- A table with
- A table is in BCNF if:
- Fourth Normal Form (4NF):
- A table is in 4NF if:
- It is in BCNF.
- It has no multi-valued dependencies; that is, a record should not contain two or more independent and multivalued facts about an entity.
- This is relevant when attributes in a table are independent but are represented together, leading to redundancy.
- Example:
- A
Studenttable withStudentID,CourseID, andLanguagewhere a student can take multiple courses and speak multiple languages, violating 4NF. These should be stored in separate tables to eliminate multi-valued dependencies.
- A
- A table is in 4NF if:
- Fifth Normal Form (5NF):
- A table is in 5NF if:
- It is in 4NF.
- It has no join dependency; that is, it cannot be decomposed into smaller tables without losing information.
- 5NF ensures that all information is split into the most granular tables without introducing redundancy or requiring unnatural joins.
- Example:
- A table that contains
StudentID,CourseID, andInstructorID, where each record represents an assignment of a student to a course with a specific instructor, and each attribute is independently meaningful. A decomposition of this table that does not result in loss of information would require 5NF.
- A table that contains
- A table is in 5NF if:
related: