120 likes | 131 Views
Learn why normalization is important, what causes anomalies, the 4 normal forms, and how to normalize a relation to 3NF and beyond. Correct anomalies and design problems with normalization.
E N D
Topics • Why normalization is needed • What causes anomalies • What the 4 normal forms are • How to normalize a relation to 3NF • Beyond 3NF - BCNF
Why Normalization • This is a Non-Normal form since it is NOT a Relation: • Multi-valued attributes or “repeating groups”
Why Normalization • Anomalies • Insertion Anomaly • Deletion Anomaly • Update Anomaly • To analyze design • To identify problems • To correct anomalies • Normalization allows us to start with a table and produce a new collection of tables that represent the same information but is free of problems.
What Causes Anomalies • Existence of functional dependencies • Key:a set of one or more attributes in a relation that identifies uniquely ALL the other attributes in the relation • Functional Dependency: a set of one or more attributes in a relation that identifies uniquely SOME of the other attributes in the relation • Transitive Dependency:aspecial kind of functional dependency. A --> B --> C
The 4 Normal Forms • 1NF (First Normal Form) • No repeating columns • 2NF (Second Normal Form) • 1NF + No sub-key => non-key • 3NF (Third Normal Form) • 2NF + No non-key => non-key • BCNF (Forth Normal Form) • 3NF + No non-key => sub-key
Converting a Relation to 3NF - An Algorithm • Determine the key to relation T • Determine the FDs in relation T • For every FD whose LHS is not a key in relation T, obtain 2 relations T1 and T2 so that T1 contains all attributes of the FD, T2 contains all the attributes of T except the RHS attributes of the FD • If the FD is transitive (A-->B-->C), always decompose B-->C first
Converting To 3NF - An Example • Key to the relation • Student_ID, Course_ID • FDs in the relation • STUDENT_ID ---> STUDENT_NAME, MAJOR • COURSE_ID ---> COURSE_TITLE, INSTRUCTOR_NAME -->OFFICE • STUDENT_ID + COURSE_ID ---> GRADE
Boyce-Codd BCNF • Every determinant is a key (3NF + no non-key -->subkey) • A student can have 1 or more majors • A student has 1 advisor per major • A major can have 1 or more advisors • An advisor advises 1 major • An advisor can advise 1 or more students in the major