120 likes | 1.22k Views
Extending ER Diagrams (4.4) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: An Application-Oriented Approach 2ed , by Kifer, Bernstein & Lewis, © Addison Wesley 2005) Basic ER Diagram Cannot Capture Specialization/ Generalization Examples
E N D
Extending ER Diagrams (4.4) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: An Application-Oriented Approach 2ed, by Kifer, Bernstein & Lewis, © Addison Wesley 2005)
Basic ER Diagram Cannot Capture Specialization/ Generalization • Examples • Doctors and Nurses are Medical Staff • Staff includes Medical staff, Secretarial staff, Housekeeping staff, etc. • Relationships might include Doctors, Medical Staff, and/or Staff • ER diagram cannot represent the fact that Staff > Medical staff > doctors • EER diagram can!
Entity Type Hierarchies • An entity type E1 is a subtype of the entity type E2 when • Every entity instance of E1 is also an instance of E2 • Every attribute in E2 is also in E1 • The opposite of a subtype is a supertype • Subtypes are related to supertypes through the IS-A relationship
IS-A IS-A Subtype / Supertype Example • Doctor is a subtype of medical-staff • Staff is a supertype of medical-staff Staff • Attributes • Staff - name, addr, salary • Med-staff - pager # • Doctor - license # Medical-Staff Admin-Staff Doctor Nurse
Attribute Inheritance • Each entity type inherits all attributes of its supertype(s) • Staff has name, address, salary • Medical staff has {n,a,s} + beeper-number • Doctor has {n, a, s, b#} + license # • In EER diagram, inherited attributes only appear once (in the highest supertype)
Generalizing Type Hierarchies • Multiple supertypes for the same subtype • A student-employee is both a student and an employee • Overlapping subtypes • Subclasses of person are student and employee • There is at least one individual who is both a student and an employee • Non-overlapping subtypes are called “disjoint”
Extended ER (EER) Diagram • IS-A relationships • Notation for disjoint (vs. overlapping) subtypes • Notation for “covering” • Can someone be staff without being Medical or administrative?
Additional Semantic Relationships • Aggregation and Composition • Collecting together related entities that represent ‘parts’ of a ‘whole’ • Aggregation (non-exclusive subpart): parts can change parents • Composition (exclusive subpart): single parent, very strong association - parts make no sense without parent • Examples: • Branch (whole) has Staff (part) Aggregation • Newspaper (whole) contains Story (part) Composition • EER representation is diamond with arrow from “part”
Exclusive Subpart = Weak Entity • A Weak Entity depends on some related entity for its existence. It has no candidate keys without including the primary key of the entity it depends on. • Example • Employee ( empNo, fname, lname salary,…) HAS Dependent (fname) • Dependent is not represented without employee • Parent’s record used to distinguish (e.g.) Jennifers
Figure 4.11 Exclusive part-of relationship in E-R: weak entities.