AnnouncementsYou’ve got a database, now what?LAMP for web applicationsHow to write PHP scriptsChapter 10Database Design – The Big Picture1 Informal Design Guidelines for Relational Databases (1)1.1 Semantics of the Relation AttributesSlide 9Slide 101.2 Redundant Information in Tuples and Update AnomaliesEXAMPLE OF AN UPDATE ANOMALYEXAMPLE OF AN INSERT ANOMALYEXAMPLE OF AN DELETE ANOMALYSlide 15Slide 16Guideline to Redundant Information in Tuples and Update Anomalies1.3 Null Values in Tuples1.4 Spurious TuplesFunctional Dependencies2.1 Functional Dependencies (1)Functional Dependencies (2)Examples of FD constraints (1)Slide 24Examples of FD constraints (2)Slide 262.2 Inference Rules for FDs (1)Inference Rules for FDs (2)Inference Rules for FDs (3)2.3 Equivalence of Sets of FDs2.4 Minimal Sets of FDs (1)Minimal Sets of FDs (2)Computing the Minimal Sets of FDs3 Normal Forms Based on Primary KeysNormal Forms Defined Informally3.1 Normalization of Relations (1)Normalization of Relations (2)3.2 Practical Use of Normal Forms3.3 Definitions of Keys and Attributes Participating in Keys (1)Definitions of Keys and Attributes Participating in Keys (2)3.2 First Normal FormSlide 42Slide 433.3 Second Normal Form (1)Second Normal Form (2)Slide 463.4 Third Normal Form (1)Third Normal Form (2)Slide 49Slide 50Slide 51Slide 524 General Normal Form Definitions (For Multiple Keys) (1)General Normal Form Definitions (2)5 BCNF (Boyce-Codd Normal Form)Slide 56Slide 57Achieving the BCNF by Decomposition (1)Achieving the BCNF by Decomposition (2)Chapter SummaryAnnouncements•Homework 1 due Friday. Slip it under my office door (1155) or put in my mailbox on 5th floor.•Program 2 has been graded ;-(•Program 3 out today, due Tuesday Nov 13•Today, Chapter 10 –Database Design TheorysYou’ve got a database, now what?•You need a database application program•Can be written in pretty much any language: Java, C++, C#, COBOL, Perl, PHP, Python,...•We don’t have time to go into each of these.•See Chapter 9.LAMP for web applicationsLinux – Apache – MySQL – PHPExample1 codeExample codeMore info on PHP: chapter 26, InternerHow to write PHP scriptsPut PHP code in/pub/www/instruction/students/<username>/URL is http://weise.cs.uwm.edu/~<username>Chapter 10Functional Dependencies and Normalization for Relational DatabasesDatabase Design – The Big PictureYou have setup the tables of a database (ie, the schema). How can you tell if it is a good design?1) Each relation schema has clear semantics2) Redundant Information is Minimized3) NULL values are not common4) No Spurious tuples following reasonable joins1 Informal Design Guidelines for Relational Databases (1)•What is relational database design?–The grouping of attributes to form "good" relation schemas• Two levels of relation schemas–The logical "user view" level–The storage "base relation" level• Design is concerned mainly with base relations• What are the criteria for "good" base relations?1.1 Semantics 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 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 semantics of attributes should be easy to interpret.A simplified COMPANY relational database schema1.2 Redundant Information in Tuples and Update Anomalies •Information is stored redundantly –Wastes storage–Causes problems with update anomalies•Insertion anomalies•Deletion anomalies•Modification anomaliesEXAMPLE OF AN 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.EXAMPLE OF AN 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.EXAMPLE OF AN 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.Two relation schemas suffering from update anomaliesGuideline to Redundant Information in Tuples and Update Anomalies•GUIDELINE 2: –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.1.3 Null Values in Tuples •GUIDELINE 3:–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)•Example with superssn• Reasons for nulls:–Attribute not applicable or invalid–Attribute value unknown (may exist)–Value known to exist, but unavailable1.4 Spurious Tuples •Bad designs for a relational database may result in erroneous results for certain JOIN operations•The "lossless join" property is used to guarantee meaningful results for join operations •GUIDELINE 4:–The relations should be designed to satisfy the lossless join condition.–No spurious tuples should be generated by doing a natural-join of any relations.Functional Dependencies2.1 Functional Dependencies (1) •Functional dependencies (FDs)–Are used to specify formal measures of the "goodness" of relational designs–And keys are used to define normal forms for relations–Are constraints that are derived from the meaning and interrelationships of the data attributes•A set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for YFunctional Dependencies (2)•X -> Y holds if whenever two tuples have the same value for X, they must have the same value for Y–For any two tuples t1 and t2 in any
View Full Document