1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Information Systems Chapter 4 Relational Databases Modelling.
Lecture 6: Design Constraints and Functional Dependencies January 21st, 2004.
1 Lecture 02: Conceptual Design Wednesday, October 6, 2010 Dan Suciu -- CSEP544 Fall 2010.
1 Relational Model and Translating ER into Relational.
1 Lecture 04 Entity/Relationship Modelling. 2 Outline E/R model (Chapter 5) From E/R diagrams to relational schemas (Chapter 5) Constraints in SQL (Chapter.
Lecture #2 October 5 th, 2000 Conceptual Modeling Administration: –HW1 available –Details on projects –Exam date –XML comment.
Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally:
1 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
Lecture #3 Functional Dependencies Normalization Relational Algebra Thursday, October 12, 2000.
Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science San Jose State University.
1 Lecture 06 The Relational Data Model. 2 Outline Relational Data Model Functional Dependencies FDs in ER Logical Schema Design Reading Chapter 8.
Relational Algebra and SQL Prof. Sin-Min Lee Department of Computer Science San Jose State University.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #7 Matthew P. Johnson Stern School of Business, NYU Spring,
1 Lecture 3: Database Modeling (continued) April 5, 2002.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #4 M.P. Johnson Stern School of Business, NYU Spring, 2008.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #5 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
Boyce-Codd NF & Lossless Decomposition Professor Sin-Min Lee.
Functional Dependencies CS 186, Spring 2006, Lecture 21 R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
Functional Dependencies and Relational Schema Design.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
E/R Diagrams and Functional Dependencies. Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need.
Lecture 08: E/R Diagrams and Functional Dependencies.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
1 Web Database The Relational Data Model Irvanizam Zamanhuri, M.Sc Computer Science Study Program Syiah Kuala University Website :
Functional Dependencies R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another. Thomas Hobbes ( )
1 Database Systems Lecture #4 Yan Pan School of Software, SYSU 2011.
Lecture 3: Conceptual Database Design and Schema Design April 12 th, 2004.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
COMP 430 Intro. to Database Systems Normal Forms Slides use ideas from Chris Ré.
1 Lecture 9: Database Design Wednesday, January 25, 2006.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
Lecture 11: Functional Dependencies
Lecture 5: Conceptual Database Design
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
Lecture 6: Design Theory
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
Cse 344 May 16th – Normalization.
Functional Dependencies and Relational Schema Design
Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design October 12 & 15, 2007.
Lecture 09: Functional Dependencies, Database Design
Lecture 8: Database Design
Lecture 07: E/R Diagrams and Functional Dependencies
Functional Dependencies
Lecture 5: The Relational Data Model
CSE544 Data Modeling, Conceptual Design
Functional Dependencies
Chapter 19 (part 1) Functional Dependencies
Terminology Product Attribute names Name Price Category Manufacturer
Lecture 08: E/R Diagrams and Functional Dependencies
Lecture 6: Functional Dependencies
Lecture 09: Functional Dependencies
Presentation transcript:

1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005

2 Outline Finish E/R diagrams (Chapter 2) –And E/R diagrams to relations (3.2, 3.3) The relational data model: 3.1 Functional dependencies: 3.4

3 Constraints in E/R Diagrams Finding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Other constraints: peoples’ ages are between 0 and 150.

4 Keys in E/R Diagrams address namessn Person Product namecategory price No formal way to specify multiple keys in E/R diagrams Underline:

5 Single Value Constraints makes v. s.

6 Referential Integrity Constraints CompanyProduct makes CompanyProduct makes Each product made by at most one company. Some products made by no company Each product made by exactly one company.

7 Other Constraints CompanyProduct makes <100 What does this mean ?

8 Weak Entity Sets Entity sets are weak when their key comes from other classes to which they are related. UniversityTeam affiliation numbersportname Notice: we encountered this when converting multiway relationships to binary relationships (last lecture)

9 Handling Weak Entity Sets UniversityTeam affiliation numbersportname Convert to a relational schema (in class)

10 The Relational Data Model Data Modeling Data Modeling Relational Schema Relational Schema Physical storage Physical storage E/R diagrams Tables: column names: attributes rows: tuples Complex file organization and index structures. Have seen this in SQL Have seen this too Discuss next

11 Terminology Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi Tuples or rows or records Attribute names Table name or relation name Products:

12 Schemas Relational Schema: –Relation name plus attribute names –E.g. Product(Name, Price, Category, Manufacturer) –In practice we add the domain for each attribute Database Schema –Set of relational schemas –E.g. Product(Name, Price, Category, Manufacturer), Company(Name, Address, Phone), This is all mathematics, not to be confused with SQL tables !

13 Instances Relational schema = R(A 1,…,A k ): Instance = relation with k attributes (of “type” R) –values of corresponding domains Database schema = R 1 (…), R 2 (…), …, R n (…) Instance = n relations, of types R 1, R 2,..., R n

14 Example Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi Relational schema:Product(Name, Price, Category, Manufacturer) Instance:

15 First Normal Form (1NF) A database schema is in First Normal Form if all tables are flat NameGPACourses Alice3.8 Bob3.7 Carol3.9 Math DB OS DB OS Math OS Student NameGPA Alice3.8 Bob3.7 Carol3.9 Student Course Math DB OS StudentCourse AliceMath CarolMath AliceDB BobDB AliceOS CarolOS Takes Course May need to add keys

16 Functional Dependencies A form of constraint –hence, part of the schema Finding them is part of the database design Also used in normalizing the relations

17 Functional Dependencies Warning: this is the most abstract, and “hardest” part of the course. This chapter in the book (3.4) is not very good COME TO CLASS, PAY ATTENTION, READ THE LECTURE NOTES !

18 Functional Dependencies Definition: If two tuples agree on the attributes then they must also agree on the attributes Formally: A 1, A 2, …, A n  B 1, B 2, …, B m A 1, A 2, …, A n B 1, B 2, …, B m

19 Typical Examples of FDs Product: name  price, manufacturer Person: ssn  name, age zip  city city, state  zip

20 Examples EmpID  Name, Phone, Position Position  Phone but not Phone  Position EmpIDNamePhonePosition E0045Smith1234Clerk E1847John9876Salesrep E1111Smith9876Salesrep E9999Mary1234Lawyer Formally, an FD holds, or does not hold on an instance:

21 In General To check A  B, erase all other columns check if the remaining relation is many-one (called functional in mathematics) Note: this is the mathematical definition of a function. Book is wrong.

22 Example EmpIDNamePhonePosition E0045Smith1234Clerk E1847John9876Salesrep E1111Smith9876Salesrep E9999Mary1234Lawyer

23 Example FD’s are constraints: On some instances they hold On others they don’t namecategorycolordepartmentprice GizmoGadgetGreenToys49 TweakerGadgetGreenToys99 Does this instance satisfy all the FDs ? name  color category  department color, category  price name  color category  department color, category  price

24 Example namecategorycolordepartmentprice GizmoGadgetGreenToys49 TweakerGadgetBlackToys99 GizmoStationaryGreenOffice-supp.59 What about this one ? name  color category  department color, category  price name  color category  department color, category  price

25 An Interesting Observation If all these FDs are true: name  color category  department color, category  price name  color category  department color, category  price Then this FD also holds: name, category  price Why ??

26 Inference Rules for FD’s Is equivalent to Splitting rule and Combing rule A1...AmB1...Bm A 1, A 2, …, A n  B 1, B 2, …, B m A 1, A 2, …, A n  B 1 A 1, A 2, …, A n  B A 1, A 2, …, A n  B m A 1, A 2, …, A n  B 1 A 1, A 2, …, A n  B A 1, A 2, …, A n  B m

27 Inference Rules for FD’s (continued) Trivial Rule Why ? A1A1 …AmAm where i = 1, 2,..., n A 1, A 2, …, A n  A i

28 Inference Rules for FD’s (continued) Transitive Closure Rule If and then Why ? A 1, A 2, …, A n  B 1, B 2, …, B m B 1, B 2, …, B m  C 1, C 2, …, C p A 1, A 2, …, A n  C 1, C 2, …, C p

29 A1A1 …AmAm B1B1 …BmBm C1C1...CpCp

30 Example (continued) Start from the following FDs: Infer the following FDs: 1. name  color 2. category  department 3. color, category  price 1. name  color 2. category  department 3. color, category  price Inferred FD Which Rule did we apply ? 4. name, category  name 5. name, category  color 6. name, category  category 7. name, category  color, category 8. name, category  price

31 Example (continued) Answers: Inferred FD Which Rule did we apply ? 4. name, category  name Trivial rule 5. name, category  color Transitivity on 4, 1 6. name, category  category Trivial rule 7. name, category  color, category Split/combine on 5, 6 8. name, category  price Transitivity on 3, 7 1. name  color 2. category  department 3. color, category  price 1. name  color 2. category  department 3. color, category  price THIS IS TOO HARD ! Let’s see an easier way.

32 Closure of a set of Attributes Given a set of attributes A 1, …, A n The closure, {A 1, …, A n } +, is the set of attributes B s.t. A 1, …, A n  B Given a set of attributes A 1, …, A n The closure, {A 1, …, A n } +, is the set of attributes B s.t. A 1, …, A n  B name  color category  department color, category  price name  color category  department color, category  price Example: Closures: name + = {name, color} {name, category} + = {name, category, color, department, price} color + = {color}

33 Closure Algorithm Start with X={A1, …, An}. Repeat until X doesn’t change do: if B 1, …, B n  C is a FD and B 1, …, B n are all in X then add C to X. Start with X={A1, …, An}. Repeat until X doesn’t change do: if B 1, …, B n  C is a FD and B 1, …, B n are all in X then add C to X. {name, category} + = { } name  color category  department color, category  price name  color category  department color, category  price Example: name, category, color, department, price Hence: name, category  color, department, price

34 Another Example Enrollment(student, major, course, room, time) student  major major, course  room course  time What else can we infer ? [in class, or at home]

35 Example Compute {A,B} + X = {A, B, } Compute {A, F} + X = {A, F, } R(A,B,C,D,E,F) A, B  C A, D  E B  D A, F  B A, B  C A, D  E B  D A, F  B In class:

36 Using Closure to Infer ALL FDs A, B  C A, D  B B  D A, B  C A, D  B B  D Example: Step 1: Compute X +, for every X: A+ = A, B+ = BD, C+ = C, D+ = D AB+ = ABCD, AC+ = AC, AD+ = ABCD ABC+ = ABD+ = ACD + = ABCD (no need to compute– why ?) BCD + = BCD, ABCD+ = ABCD A+ = A, B+ = BD, C+ = C, D+ = D AB+ = ABCD, AC+ = AC, AD+ = ABCD ABC+ = ABD+ = ACD + = ABCD (no need to compute– why ?) BCD + = BCD, ABCD+ = ABCD Step 2: Enumerate all FD’s X  Y, s.t. Y  X + and X  Y =  : AB  CD, AD  BC, ABC  D, ABD  C, ACD  B