DOC PREVIEW
UW-Milwaukee COMPSCI 557 - Lecture Notes

This preview shows page 1-2-3-4-28-29-30-31-57-58-59-60 out of 60 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 60 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Announcements• Homework 1 due Friday. Slip it under my office door (1155) or put in my mailbox on 5thfloor.• 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 – PHPExample1codeExample 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 meaningand 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 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 attributesExamples of FD constraints (1) • 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} -> HOURSExamples of FD constraints (2)• An FD is a property of the attributes in the schema R• The 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])FD’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 database2.2 Inference Rules for FDs (1) • Given a set of FDs F, we can infer additional FDs that hold whenever the FDs in F hold• Armstrong's inference rules:–IR1. (Reflexive) If Y subset-of X, then X -> Y–IR2. (Augmentation) If X -> Y, then XZ -> YZ• (Notation: XZ stands for X U Z)–IR3. (Transitive) If X -> Y and Y -> Z, then X -> Z• IR1, IR2, IR3 form a sound and complete set of inference rules– These are rules hold and all other rules that hold


View Full Document

UW-Milwaukee COMPSCI 557 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?