1 / 33

Normalization

Normalization. Lecture 10. Intoduction.

susan
Download Presentation

Normalization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Normalization Lecture 10

  2. Intoduction • In the field of relational database design, normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain undesirable characteristics—insertion, update, and deletion anomalies—that could lead to a loss of data integrity.

  3. Definition “ Normalization is the process of successively reducing relations with anomalies to produce smaller, well structured relations”

  4. Goals • Minimize Data Redundancy • Simplify the enforcement of referential integrity • Make it easier to maintain data(Insert, Update, Delete) • Provide a better design that is an improved representation of the real world and a stronger basis for future growth

  5. Informal Design Guidelines for Relational Databases • We first discuss informal guidelines for good relational design • Then we discuss formal concepts of functional dependencies and normal forms • 1NF (First Normal Form) • 2NF (Second Normal Form) • 3NF (Third Normal Form) • BCNF (Boyce-Codd Normal Form)

  6. Semantics of the Relation Attributes • GUIDELINE 1: Informally, each tuple in a relation should represent one entity. • Attributes of different entities (EMPLOYEEs, DEPARTMENTs, PROJECTs) should not be mixed in the same relation • Only foreign keys should be used to refer to other entities • Entity and relationship attributes should be kept apart as much as possible. • Bottom Line:Design a schema that can be explained easily relation by relation. The attributes should be easy to interpret.

  7. A simplified COMPANY relational database schema

  8. Anomalies In Relational Database • Insertion anomalies • Deletion anomalies • Modification anomalies (Update Anomalies)

  9. INSERT ANOMALY • Consider the relation: • EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours) • Insert Anomaly: • Cannot insert a project unless an employee is assigned to it. • Conversely • Cannot insert an employee unless a he/she is assigned to a project.

  10. DELETE ANOMALY • Consider the relation: • EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours) • Delete Anomaly: • When a project is deleted, it will result in deleting all the employees who work on that project. • Alternately, if an employee is the sole employee on a project, deleting that employee would result in deleting the corresponding project.

  11. UPDATE ANOMALY • Consider the relation: • EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours) • Update Anomaly: • Changing the name of project number P1 from “Billing” to “Customer-Accounting” may cause this update to be made for all 100 employees working on project P1.

  12. Two relation schemas suffering from update anomalies

  13. Base Relations EMP_DEPT and EMP_PROJ formed after a Natural Join : with redundant information

  14. GUIDELINE 1: • Design a schema that does not suffer from the insertion, deletion and update anomalies. • If there are any anomalies present, then note them so that applications can be made to take them into account.

  15. GUIDELINE 2: • Relations should be designed such that their tuples will have as few NULL values as possible • Attributes that are NULL frequently could be placed in separate relations (with the primary key) •  Reasons for nulls: • Attribute not applicable or invalid • Attribute value unknown (may exist) • Value known to exist, but unavailable

  16. Functional Dependencies • A set of attributes X functionallydetermines a set of attributes Y if the value of X determines a unique value for Y • Written as X -> Y

  17. Examples of FD constraints • Social security number determines employee name • SSN -> ENAME • Project number determines project name and location • PNUMBER -> {PNAME, PLOCATION} • Employee ssn and project number determines the hours per week that the employee works on the project • {SSN, PNUMBER} -> HOURS

  18. Example

  19. Partial Functional Dependency • Partial Functional Dependency Indicates that if A and B are attributes of a table , B is partially dependent on A if there is some attribute that can be removed from A and yet the dependency still holds. Say for Ex, consider the following functional dependency that exists in the Tbl_Staff table: StaffID,Name -------> BranchID BranchID is functionally dependent on a subset of A (StaffID,Name), namely StaffID.

  20. Transitive dependency • A transitive dependency is an indirect functional dependency, one in which X→Z only by virtue of X→Y and Y→Z.

  21. Example

  22. Normalization Steps and Methods

  23. Normal Forms: Review • Unnormalized – There are multivalued attributes or repeating groups • 1 NF – No multivalued attributes or repeating groups. • 2 NF – 1 NF plus no partial dependencies • 3 NF – 2 NF plus no transitive dependencies

  24. First Normal Form • Disallows • Multivalued attributes • Considered to be part of the definition of relation

  25. Second Normal Form • Definitions • Prime attribute: An attribute that is member of the primary key K • Full functional dependency: a FD Y -> Z where removal of any attribute from Y means the FD does not hold any more • A relation schema R is in second normal form (2NF) if every non-prime attribute A in R is fully functionally dependent on the primary key • R can be decomposed into 2NF relations via the process of 2NF normalization

  26. Examples: • {SSN, PNUMBER} -> HOURS is a full FD since neither SSN -> HOURS nor PNUMBER -> HOURS hold • {SSN, PNUMBER} -> ENAME is not a full FD (it is called a partial dependency ) since SSN -> ENAME also holds

  27. Third Normal Form • A relation schema R is in third normal form (3NF) if it is in 2NF and no non-prime attribute A in R is transitively dependent on the primary key • Disallows • Transitive functional dependency: a FD X -> Z that can be derived from two FDs X -> Y and Y -> Z

  28. Examples • SSN -> DMGRSSN is a transitive FD • Since SSN -> DNUMBER and DNUMBER -> DMGRSSN hold • SSN -> ENAME is non-transitive • Since there is no set of attributes X where SSN -> X and X -> ENAME

More Related