Normalization Flashcards
What is normalization in relational schemas?
A process to eliminate redundancies and anomalies by decomposing schemas into smaller, well-structured relations
Main types of anomalies in relational schemas
- Redundancy
- Update Anomaly
- Deleyion anomaly
- Insertion anomaly
Functional dependency (FD)
Constraint where one attribute uniquely determines another
EmployeeID —> Salary
Candidate Key
Minimal set of attributes that uniquely identifies a tuple (row) in a relation (table)
EMPLOYEE(EmployeeID, Name, Department)
EmployeeID is a candidate key because it uniquely identifies employees.
Transitive Dependency
Non-prime attribute depends on another non-prime attribute indirectly through a candiate key
EmployeeID depends on Department, Department depends on manager, manager is transitively dependent on EmployeeID
1NF
A relation is in 1NF is all attributes contain atomic values (No nested or multivalued attributes)
NO: City: Boston, Cambridge
2NF
A relation is in 2NF if it is in 1NF and has no non-prime attribute partially dependent on a candidate key
Remove partial dependencies from attributes
If we have StudentID, StudentName, CourseID, CourseName, and Grade:
Remove:
StudentName and CourseName
2NF:
StudentID, CourseID and Grade because
- StudentName is non-prime
- CourseName is non-prime
And they are both depend partially on the composite key (one of the keys in the composite key group)
3NF
A relation is in 3NF if it is in 2NF and has no transitive dependency of non-prime attributes on any candidate key
Remove transitive dependencies from attributes
EmployeeID, Name, DepartmentID, DepartmentName
DepartmentName depends on EmployeeID indirectly
Solution
Remove DepartName
EmployeeID, Name DepartmentID
this is why we only see what is absolutely necessary to identify
How do you normalize a relation with multivalued attributes (1NF violation)
Split multivalued attribute into a separate relation (table) with a foreign key referencing the original relation
How do you resolve partial dependencies (2NF violation)
Move attributes that depend only on part of a composite key into a separate relation
How do you handle transitive dependencies (3NF violation)
Move attributes with transitive dependencies into separate relations
Normalize EMPLOYEES(EmployeeID, Name, Salary, Department)
- EMP_SALARY(EmployeeID, Salary)
- EMP_DEPARTMENT(EmployeeID, Department)
Normalize BOOKS relation with FDs:
(Title → Author, Genre and Title, Copy → Shelf)
Split into:
* BOOKS(Title, Author, Genre)
* COPIES(Title, Copy, Shelf)
Lossless Decomposition
Original table can be reconstructed by joining the smaller tables w/out loss of data
What is FD preservation in decomposition?
Ensuring all functional dependencies in the original schema are maintained in the decomposed schema