Presentation is loading. Please wait.

Presentation is loading. Please wait.

E NTITY R ELATIONSHIP D IAGRAMS Joe Meehean 1. E NTITY R ELATIONSHIP M ODEL Entity type an object (noun) e.g., student attributes (e.g., last name) Relationship.

Similar presentations


Presentation on theme: "E NTITY R ELATIONSHIP D IAGRAMS Joe Meehean 1. E NTITY R ELATIONSHIP M ODEL Entity type an object (noun) e.g., student attributes (e.g., last name) Relationship."— Presentation transcript:

1 E NTITY R ELATIONSHIP D IAGRAMS Joe Meehean 1

2 E NTITY R ELATIONSHIP M ODEL Entity type an object (noun) e.g., student attributes (e.g., last name) Relationship association between entity types bidirectional relationship between entities e.g., students take course offerings Student Last name First name Student ID Verb 2

3 C OLLEGE E XAMPLE Student Last name First name Student ID Course Name Number Credits Faculty Last name First name Faculty ID Offering Section # Room Time 3 Has Teach Enroll

4 R ELATIONSHIP C ARDINALITY Limits the number of objects in a relationship Options 0 1 Many (M) Example: Course offering a course offering can have only one instructor an instructor can teach many course offerings a course may not be offered at all (0 offerings) 4

5 R ELATIONSHIP C ARDINALITY Relationships have both a minimum and maximum cardinality Minimum cardinality least possible number of entities involved e.g., course may not be offered at all (0) Maximum cardinality most possible number of entities involved e.g., Course may be offered many times (M) 5

6 Student Last name First name Student ID Course Name Number Credits Faculty Last name First name Faculty ID Offering Section # Room Time 6 Has Teaches Enroll Min Max C OLLEGE E XAMPLE 1 0 Many

7 Student Last name First name Student ID Course Name Number Credits Faculty Last name First name Faculty ID Offering Section # Room Time 7 Has Teaches Enroll

8 Student Last name First name Student ID Course Name Number Credits Faculty Last name First name Faculty ID Offering Section # Room Time 8 Has Teaches Enroll

9 C ARDINALITY C LASSIFICATIONS Mandatory Min cardinality >= 1 Example An offering must have a course An offering must have a faculty instructor 9 Course Name Number Credits Offering Section # Room Time Has

10 C ARDINALITY C LASSIFICATIONS Optional Min cardinality = 0 Example A faculty member does not need to teach any offerings A student does not need to take any offerings 10 Faculty Last name First name Faculty ID Offering Section # Room Time 10 Teaches

11 C ARDINALITY C LASSIFICATIONS Single-valued (functional) Max cardinality of 1 Example An offering can only have 1 course An offering can only have 1 instructor 11 Course Name Number Credits Offering Section # Room Time Has

12 C ARDINALITY C LASSIFICATIONS One to Many (1-M) max cardinality = 1 in one direction max cardinality > 1 in the other Example Faculty can teach many offerings Each offering must have only one teacher 12 Faculty Last name First name Faculty ID Offering Section # Room Time Teaches

13 C ARDINALITY C LASSIFICATIONS Many to Many (M - N) max cardinality > 1 in one direction max cardinality > 1 in the other Example Students can enroll in many offerings Offering can have many students enrolled Student Last name First name Student ID Offering Section # Room Time Enroll

14 C ARDINALITY C LASSIFICATIONS One to One (1 – 1) max cardinality = 1 in one direction max cardinality = 1 in the other Example Faculty can be married to at most one other faculty member Faculty Last name First name Faculty ID Married

15 Q UESTIONS 15

16 P RIMARY K EYS Unique value that identifies an entity Student -> Student ID Autopart -> Part # Employee -> SSN Underlined in ER Diagrams 16 Faculty Faculty ID Last name First name

17 W EAK E NTITIES Borrows all or part of its primary key from another entity identification dependency Identifying Relationship relationship that provides part of a primary key 17 Room Room Nr Capacity Building Building ID Name Location Contains Solid Line Diagonal Lines

18 A SSOCIATIVE E NTITY T YPE Weak entity that depends on two or more entities for its primary key 18 Student Student ID Last name First name Offering Offering # Room Time Earned Transcript Entry Grade Credits Earned Records Enroll

19 1-M AND M-N R ELATIONSHIPS Can convert a M-N relationship to two 1-M relationships Add a associative entity type Replace M-N relationship with 2 identifying relationships 19 Student Student ID Last name First name Offering Offering # Room Time Enroll

20 1-M AND M-N R ELATIONSHIPS Can convert a M-N relationship to two 1-M relationships Add a associative entity type Replace M-N relationship with 2 identifying relationships 20 Student Student ID Last name First name Offering Offering # Room Time Earned Transcript Item Grade Credits Earned Records

21 R ELATIONSHIPS WITH A TTRIBUTES Relationships can have attributes too Most likely to occur with M-N relationships 21 Student Student ID Last name First name Offering Offering # Room Time Enroll Grade Earned

22 S ELF -R EFERENCING R ELATIONSHIPS Relationship between members of the same entity 22 Faculty Last name First name Faculty ID Married Course Name Number Credits PrereqTo

23 Q UESTIONS 23

24 G ENERALIZATION H IERARCHIES Entity Inheritance sharing of attributes between supertype and subtype subtype inherits attributes from supertype 24 Student Major Grad Date Faculty Department Office College People College ID Last name First name Solid Line With Arrow

25 G ENERALIZATION C ONSTRAINTS Disjointness an entity can be one and only one subtype College People is not disjoint 25 Course Number Name Credits Lab Course Lab Room Lab Credits Intership Company Supervisor D “D” for Disjoint

26 G ENERALIZATION C ONSTRAINTS Completeness every entity of a supertype must also be a subtype the Course generalization is not Complete some courses are neither a lab or an internship 26 Student Major Grad Date Faculty Department Office College People College ID Last name First name C “C” for Complete

27 M ORE G ENERALIZATION Multiple levels of inheritance is OK Generalizations can be Disjoint Complete Both Neither 27 Student Major Grad Date Faculty Department Office College People College ID Last name First name C Domestic SSN Home State International Visa Expiration Date D,C

28 P REGUNTAS O I NQUIETUDES ? 28 ?

29 P ROBLEMS W ITH ER M ODELS Fan Trap pathway between certain entity rows is ambiguous may exist where two or more 1-M relationships fan out from the same entity e.g., Which employees work in sales? 29 Managers Departments Heads Employees Oversees

30 P ROBLEMS W ITH ER M ODELS Fan Trap fix by restructure of diagram to better represent reality e.g., Which employees work in sales? 30 Managers Departments Heads Employees Has

31 P ROBLEMS W ITH ER M ODELS Chasm Trap relationship implied but pathway does not always exist e.g., Which retailers offer T-Mobile? 31 Retail Store Location Has Phone Plans Has

32 P ROBLEMS W ITH ER M ODELS Chasm Trap add in the missing relationship e.g., Which retailers offer T-Mobile? 32 Retail Store Location Has Phone Plans Has Offers

33 ER D IAGRAM R ULES Names All entity types, relationships and attributes are named Entity type names are unique Attribute names are unique within entity types and relationships Attribute names in a subtype do not match inherited attribute names Content All entity types have a primary key Cardinality is given for both entity types in a relationship 33

34 ER D IAGRAM R ULES Connection All entity types participate in a relationship except those in a generalization hierarchy Each generalization hierarchy participates in at least one relationship with an entity type not in the generalization hierarchy All relationships connect two entity types Relationships are not connected to other relationships Redundant foreign keys are not used foreign keys are primary keys from other entities 34

35 ER D IAGRAM R ULES Identification Dependency Weak entities have at least one identifying relationship Identifying relationships must have least one weak entity A weak entity’s min-max cardinality must be 1 for its identifying relationship 35

36 36 Find the errors in the following diagram

37 Has- Empl Has In 37 Parts Part# Description Quantity Distributor Dist# Name Address Motorcycle Quantity Style Quantity Has- JobTitle Order Part# Quantity Order Order# Date $Total Supplier Supplier# Name Address Employee Employee# Name Years Has Years JobTitle Position# Name BaseSalary Supplies Sales Rep

38 Has- Empl Has In 38 Parts Part# Description Quantity Distributor Dist# Name Address Motorcycle Quantity Style Quantity Has- JobTitle Order Part# Quantity Order Order# Date $Total Supplier Supplier# Name Address Employee Employee# Name Years Has Years JobTitle Position# Name BaseSalary Supplies Sales Rep

39 39 Fix the errors in the previous diagram

40 Has- Empl Has In 40 Parts Part# Description Quantity Distributor Dist# Name Address Motorcycle ID# Quantity Style Has- JobTitle OrderItem Quantity Order Order# Date $Total Supplier Supplier# Name Address Employee Employee# Name Years Has Years JobTitle Position# Name BaseSalary Supplies In Sales Rep

41 P REGUNTAS O I NQUIETUDES ? 41 ?


Download ppt "E NTITY R ELATIONSHIP D IAGRAMS Joe Meehean 1. E NTITY R ELATIONSHIP M ODEL Entity type an object (noun) e.g., student attributes (e.g., last name) Relationship."

Similar presentations


Ads by Google