All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.

Information Report

Category:
## Graphic Art

Published:

Views: 0 | Pages: 6

Extension: PDF | Download: 0

Share

Related documents

Description

Announcements 2 Relational Database Design CPS 216 Advanced Database Systems DB2 accounts have been set up Let me know if you have not received an from me regarding your account Recitation session

Transcript

Announcements 2 Relational Database Design CPS 216 Advanced Database Systems DB2 accounts have been set up Let me know if you have not received an from me regarding your account Recitation session this Friday (January 17) on E/R database design and review of relational algebra and design theory Office hours Me (D327): Wed. 3:35-4:35pm & Fri. 2:00-3:00pm TA (D328): Tue. & Thu. 12:00-1:00pm Database (schema) design 3 Entity-relationship (E/R) model 4 Understand the real-world domain being modeled Specify it using a database design model Design models are especially convenient for schema design, but are not necessarily implemented by DBMS Popular ones include Entity/Relationship (E/R) model Object Definition Language (ODL) Translate the design to the data model of DBMS Relational, XML, object-oriented, etc. Apply database design theory to check the design Create DBMS schema Historically very popular Primarily a design model; not implemented by any major DBMS nowadays Can think of as a watered-down object-oriented design model E/R diagrams represent designs E/R example 5 ODL (Object Definition Language) 6 SID name Students Enroll Courses CID Entity: a thing, like a record or an object Entity set (rectangle): a collection of things of the same type, like a relation of tuples or a class of objects Relationship: an association among two or more entities Relationship set (diamond): a set of relationships of the same type; an association among two or more entity sets Attributes (ovals): properties of entities or relationships, like attributes of tuples or objects title Standardized by ODMG (Object Data Management Group) Comes with a declarative query language OQL (Object Query Language) Implemented by OODBMS (Object-Oriented DataBase Management Systems) Object oriented Based on C ++ syntax Class declarations represent designs ODL example 7 Not covered in this lecture 8 class Student { attribute integer SID; attribute string name; relationship Set Course enrolledin inverse Course::students; }; class Course { attribute string CID; attribute string title; relationship Set Student students inverse Student::enrolledIn; }; Easy to map them to C ++ classes ODL attributes correspond to attributes of objects; complex types are allowed ODL relationships can be mapped to pointers to other objects (e.g., Set Course set of pointers to objects of Course class) E/R and ODL design Translating E/R and ODL designs into relational designs Reference book (GMUW) has all the details E/R design and E/R-relational translation will be covered in recitation session this Friday Next: relational design theory Relational model: review 9 Keys 10 A set of attributes K is a key for a relation R if A database is a collection of relations (or tables) Each relation has a list of attributes (or columns) Each attribute has a domain (or type) Each relation contains a set of tuples (or rows) In no instance of R will two different tuples agree on all attributes of K That is, K is a tuple identifier No proper subset of K satisfies the above condition That is, K is minimal Example: Student (SID, name, age, GPA) SID is a key of Student {SID, name} is not a key (not minimal) Schema vs. data 11 More examples of keys 12 Student Is name a key of Student? SID name age GPA 142 Bart Milhouse Lisa Ralph Yes? Seems reasonable for this instance No! Student names are not unique in general Key declarations are part of the schema Enroll (SID, CID) {SID, CID} Address (street_address, city, state, zip) {street_address, city, state} {street_address, zip} Course (CID, title, room, day_of_week, begin_time, end_time) {CID, day_of_week, begin_time} {CID, day_of_week, end_time} {room, day_of_week, begin_time} {room, day_of_week, end_time} Not a good design, and we will see why later Usage of keys More constraints on data, fewer mistakes Look up a row by its key value Many selection conditions are key = value Pointers Example: Enroll (SID, CID) SID is a key of Student CID is a key of Course An Enroll tuple links a Student tuple with a Course tuple Many join conditions are key = key value stored in another table 13 Motivation for a design theory SID name CID 142 Bart CPS Bart CPS Lisa CPS Lisa CPS230 Why is this design is bad? This design has redundancy, because the name of a student is recorded multiple times, once for each course the student is taking Why is redundancy bad? Wastes space, complicates updates, and promotes inconsistency How about a systematic approach to detecting and removing redundancy in designs? Dependencies, decompositions, and normal forms 14 Functional dependencies A functional dependency (FD) has the form X Y, where X and Y are sets of attributes in a relation R X Y means that whenever two tuples in R agree on all the attributes in X, they must also agree on all attributes of Y Must be b X Y Z a b c a b?? Could be anything 15 FD examples Address (street_address, city, state, zip) street_address, city, state zip zip city, state zip, state zip? This is a trivial FD Trivial FD: LHS RHS zip state, zip? This is non-trivial, but not completely non-trivial Completely non-trivial FD: LHS RHS = 16 Keys redefined using FD s 17 Reasoning with FD s 18 A set of attributes K is a key for a relation R if K all (other) attributes of R That is, K is a super key No proper subset of K satisfies the above condition That is, K is minimal Given a relation R and a set of FD s F Does another FD follow from F? Are some of the FD s in F redundant (i.e., they follow from the others)? Is K a key of R? What are all the keys of R? Attribute closure Given R, a set of FD s F that hold in R, and a set of attributes Z in R: The closure of Z (denoted Z + ) with respect to F is the set of all attributes functionally determined by Z Algorithm for computing the closure Start with closure = Z If X Y is in F and X is already in the closure, then also add Y to the closure Repeat until no more attributes can be added 19 A more complex example StudentGrade (SID, name, , CID, grade) SID name, SID SID, CID grade Not a good design, and we will see why later 20 Example of computing closure 21 Using attribute closure 22 F includes: SID name, SID SID, CID grade { CID, } + =? SID Add SID; closure is now { CID, , SID } SID name, Add name, ; closure is now { CID, , SID, name } SID, CID grade Add grade; closure is now all the attributes in StudentGrade Given a relation R and set of FD s F Does another FD X Y follow from F? Compute X + with respect to F If Y X +, then X Y follow from F Is K a key of R? Compute K + with respect to F If K + contains all the attributes of R, K is a super key Still need to verify that K is minimal (how?) Useful rules of FD s Armstrong s axioms Reflexivity: If Y X, then X Y Augmentation: If X Y, then XZ YZ for any Z Transitivity: If X Y and Y Z, then X Z Rules derived from axioms Splitting: If X YZ, then X Y and X Z Combining: If X Y and X Z, then X YZ 23 Non-key FD s Consider a non-trivial FD X Y where X is not a super key Since X is not a super key, there are some attributes (say Z) that are not functionally determined by X X Y Z a b c1 a b c2 The fact that a is always associated with b is recorded in multiple rows: redundancy! 24 Example of redundancy 25 Decomposition 26 StudentGrade (SID, name, , CID, grade) SID name, SID name CID grade SID name CID grade 142 Bart CPS216 B- 142 Bart CPS214 B 123 Milhouse CPS216 B+ 857 Lisa CPS216 A+ 857 Lisa CPS230 A+ 456 Ralph CPS214 C SID name 142 Bart 123 Milhouse 857 Lisa 456 Ralph Eliminates redundancy To get back to the original relation: SID CID grade 142 CPS216 B- 142 CPS214 B 123 CPS216 B+ 857 CPS216 A+ 857 CPS230 A+ 456 CPS214 C Unnecessary decomposition 27 Bad decomposition 28 SID name 142 Bart 123 Milhouse 857 Lisa 456 Ralph SID name 142 Bart 123 Milhouse 857 Lisa 456 Ralph SID Fine: join returns the original relation Unnecessary: no redundancy is removed, and now SID is stored twice! SID CID 142 CPS CPS CPS CPS CPS CPS214 SID CID grade 142 CPS216 B- 142 CPS214 B 123 CPS216 B+ 857 CPS216 A+ 857 CPS230 A+ 456 CPS214 C SID grade 142 B- 142 B 123 B+ 857 A+ 857 A+ 456 C Association between CID and grade is lost Join returns more rows than the original relation Questions about decomposition When to decompose How to come up with a correct decomposition 29 An answer: A relation R is in Boyce-Codd Normal Form if For every non-trivial FD X Y in R, X is a super key That is, all FDs follow from key other attributes When to decompose As long as some relation is not in How to come up with a correct decomposition Always decompose on a violation Then it is guaranteed to be a correct decomposition! 30 decomposition algorithm 31 decomposition example 32 Find a violation That is, a non-trivial FD X Y in R where X is not a super key of R Decompose R into R 1 and R 2, where R 1 has attributes X Y R 2 has attributes X Z, where Z contains all attributes of R that are in neither X nor Y Repeat until all relations are in StudentGrade (SID, name, , CID, grade) violation: SID name, Student (SID, name, ) Grade (SID, CID, grade) Another example 33 Recap 34 StudentGrade (SID, name, , CID, grade) violation: SID StudentID ( , SID) StudentGrade ( , name, CID, grade) violation: name StudentName ( , name) Grade ( , CID, grade) Functional dependencies: generalization of keys Non-key functional dependencies: a source of redundancy decomposition: a method of removing redundancies due to FD s : schema in this normal form has no redundancy due to FD s Not covered in this lecture: many other types of dependencies (e.g., MVD) and normal forms (e.g., 4NF) GMUW has all the details Relational design theory was a big research area in the 1970 s, but there is not much now

Recommended

15 pages

36 pages

49 pages

15 pages

Related Search

We Need Your Support

Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks