Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from...

11
Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information and Management, by Connolly and Begg, © Addison Wesley 2010)

Transcript of Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from...

Page 1: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Extending ER Diagrams (13)

CPSC 356 Database

Ellen Walker

Hiram College

(Includes figures from Database Systems: A Practical Approach to Design, Information and Management, by Connolly and Begg, © Addison Wesley 2010)

Page 2: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

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!

Page 3: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Entity Type Hierarchies

• An entity type E1 is a subclass 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 subclass is a superclass• Subclasses are related to superclasses

through the IS-A relationship

Page 4: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

When to Use?

• When you have an entity that needs to have extra / different attributes “sometimes”

• When you have two entities that overlap on many or most of their attributes

Page 5: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Subclass / Superclass Example

• Doctor is a subclass of medical-staff• Staff is a superclass of medical-staff

• Attributes – Staff - name, addr, salary– Med-staff - pager #– Doctor - license #

Staff

Medical-Staff Admin-Staff

Doctor Nurse

Page 6: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Attribute Inheritance

• Each entity type inherits all attributes of its superclass(es)– 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 superclass)

Page 7: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Generalizing Type Hierarchies

• Multiple superclasses for the same subclass– A student-employee is both a student and an

employee

• Overlapping subclasses– Subclasses of person are student and employee– There is at least one individual who is both a

student and an employee

• Non-overlapping subclasses are called “disjoint”

Page 8: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Specialization of Staff (13.2)

Page 9: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

Extended ER (EER) Diagram

• IS-A relationships• Notation for disjoint (vs. overlapping)

subclasses– Disjoint = “or”, overlapping = “and”

• Notation for “covering”– Can someone be staff without being Medical or

administrative?– If so, “optional”; if not “mandatory”

Page 10: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

More Staff Types (13.3)

Page 11: Extending ER Diagrams (13) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: A Practical Approach to Design, Information.

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”– Open for aggregation, closed for composition – (see 13.9, 13.10)