Chapter 15Chapter OutlineSlide 3Informal Design Guidelines for Relational Databases (1)Informal Design Guidelines for Relational Databases (2)Semantics of the Relation AttributesPowerPoint PresentationRedundant Information in Tuples and Update AnomaliesEXAMPLE OF AN UPDATE ANOMALYEXAMPLE OF AN INSERT ANOMALYEXAMPLE OF AN DELETE ANOMALYSlide 12Slide 13Guideline to Redundant Information in Tuples and Update AnomaliesNull Values in Tuples2.1 Functional Dependencies (1)Functional Dependencies (2)Examples of FD constraints (1)Examples of FD constraints (2)Slide 20Normal Forms Based on Primary KeysNormalization of Relations (1)Normalization of Relations (2)Practical Use of Normal FormsDefinitions of Keys and Attributes Participating in KeysSlide 26First Normal FormSlide 28Slide 29Second Normal FormSlide 31Slide 32Third Normal FormSlide 34Slide 35Normal Forms Defined InformallySlide 37General Normal Form Definitions (For Multiple Keys)General Normal Form DefinitionsBCNF (Boyce-Codd Normal Form)Slide 41Chapter SummaryChapter 15Functional Dependencies and Normalization for Relational Databases2Chapter Outline1. Informal Design Guidelines for Relational Databases1.1 Semantics of the Relation Attributes1.2 Redundant Information in Tuples and Update Anomalies1.3 Null Values in Tuples1.4 Spurious Tuples2. Functional Dependencies (FDs)3Chapter Outline3 Normal Forms Based on Primary Keys3.1 Normalization of Relations 3.2 Practical Use of Normal Forms 3.3 Definitions of Keys and Attributes Participating in Keys 3.4 First Normal Form3.5 Second Normal Form3.6 Third Normal Form4 General Normal Form Definitions (For Multiple Keys)5 BCNF (Boyce-Codd Normal Form)4Informal Design Guidelines for Relational Databases (1)What is relational database design?The grouping of attributes to form "good" relation schemas Two levels of relation schemasThe logical "user view" levelThe storage "base relation" level Design is concerned mainly with base relations What are the criteria for "good" base relations?5Informal Design Guidelines for Relational Databases (2)We first discuss informal guidelines for good relational designThen 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)6Semantics of the Relation Attributes GUIDELINE 1: Informally, each tuple in a relation should represent one entity or relationship instance. (Applies to individual relations and their attributes).Attributes of different entities (EMPLOYEEs, DEPARTMENTs, PROJECTs) should not be mixed in the same relationOnly foreign keys should be used to refer to other entitiesEntity 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 semantics of attributes should be easy to interpret.A simplified COMPANY relational database schema8Redundant Information in Tuples and Update Anomalies Information is stored redundantly Wastes storageCauses problems with update anomaliesInsertion anomaliesDeletion anomaliesModification anomalies9EXAMPLE OF AN UPDATE ANOMALYConsider 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.10EXAMPLE OF AN INSERT ANOMALYConsider the relation:EMP_PROJ(Emp#, Proj#, Ename, Pname, No_hours)Insert Anomaly:Cannot insert a project unless an employee is assigned to it.ConverselyCannot insert an employee unless a he/she is assigned to a project.11EXAMPLE OF AN DELETE ANOMALYConsider 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.12Two relation schemas suffering from update anomalies13Base Relations EMP_DEPT and EMP_PROJ formed after a Natural Join : with redundant information14Guideline to Redundant Information in Tuples and Update AnomaliesGUIDELINE 2: Design a schema that does not suffer from the insertion, deletion and update anomalies.15Null Values in Tuples GUIDELINE 3:Relations should be designed such that their tuples will have as few NULL values as possibleAttributes that are NULL frequently could be placed in separate relations (with the primary key) Reasons for nulls:Attribute not applicable or invalidAttribute value unknown (may exist)Value known to exist, but unavailable162.1 Functional Dependencies (1) Functional dependencies (FDs)Are used to specify formal measures of the "goodness" of relational designsAnd keys are used to define normal forms for relationsAre constraints that are derived from the meaning and interrelationships of the data attributesA set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for Y17Functional Dependencies (2)X -> Y holds if whenever two tuples have the same value for X, they must have the same value for YFor any two tuples t1 and t2 in any relation instance r(R): If t1[X]=t2[X], then t1[Y]=t2[Y]X -> Y in R specifies a constraint on all relation instances r(R)Written as X -> Y; can be displayed graphically on a relation schema as in Figures. ( denoted by the arrow ).FDs are derived from the real-world constraints on the attributes18Examples of FD constraints (1) Social security number determines employee nameSSN -> ENAMEProject number determines project name and locationPNUMBER -> {PNAME, PLOCATION}Employee ssn and project number determines the hours per week that the employee works on the project{SSN, PNUMBER} -> HOURS19Examples of FD constraints (2)An FD is a property of the attributes in the schema RThe constraint must hold on every relation instance r(R)If K is a key of R, then K functionally determines all attributes in R (since we never have two distinct tuples with t1[K]=t2[K])20FD’s are a property of the meaning of data and hold at all times: certain FD’s can be ruled out based on a given state of the database21Normal
View Full Document