Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE 480: Database Systems Lecture 4: Enhanced Entity-Relationship Modeling Reference: Read Chapter 8.1 – 8.5 of the textbook.

Similar presentations


Presentation on theme: "1 CSE 480: Database Systems Lecture 4: Enhanced Entity-Relationship Modeling Reference: Read Chapter 8.1 – 8.5 of the textbook."— Presentation transcript:

1 1 CSE 480: Database Systems Lecture 4: Enhanced Entity-Relationship Modeling Reference: Read Chapter 8.1 – 8.5 of the textbook

2 2 Announcements l Class Project –Each group must email the instructor by next Tuesday your group members  If your group has only 2 members, state whether you’re willing to accept a third member –If you don’t have a group yet, email me too. I’ll try to set up one for you.

3 3 Why EER? l ER diagram has limitations in terms of accurately reflecting the data properties and constraints l EER, which stands for Enhanced ER includes all the modeling concepts of basic ER with the following additional concepts –subclasses/superclasses –type inheritance –shared subclasses and multiple inheritance –categories (UNION types)

4 4 Why Subclasses and Superclasses? l An entity type may have additional subgroupings: –EMPLOYEE may be further grouped into:  SECRETARY, ENGINEER, TECHNICIAN –Based on job type  SALARIED_EMPLOYEE, HOURLY_EMPLOYEE –Based on method of pay l EER diagram extends ER diagram to represent these additional subgroupings –Each subgrouping is called a subclass of EMPLOYEE –EMPLOYEE is the superclass of these subclasses

5 5 Is-A Relationships in EER l Subclass-superclass relationships are also called IS-A relationships –SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, …. Subclass Superclass Subclass1 Superclass Subclass2 Subclass3

6 6 Specialization l A superclass can have several specializations –EMPLOYEE has 3 specializations l Some specializations have only 1 subclass (e.g., Manager)

7 7 Is-A vs 1-to-1 Relationship EMPLOYEEDEPARTMENT MANAGES 1 1 EMPLOYEETECHNICIAN  In a 1-1 relationship, two distinct entities are related  In a subclass-superclass relationship, the subclass member is the same entity as the superclass member but in a distinct specific role

8 8 Subclasses and Superclasses l A subclass entity must be a member of the superclass l But a superclass entity does not have to be a member of any of its subclasses

9 9 Why do we need Subclass/Superclass? l Certain attributes may apply to some but not all entities of the superclass –Ex: Typing speed is an attribute of SECRETARY but not a TECHNICIAN l Certain relationship types are applicable to some entities but not others –HOURLY_EMPLOYEE has a relationship with TRADE_UNION; SALARIED_EMPLOYEE does not have such a relationship

10 10 Attributes of a Subclass l Local attributes: TypingSpeed of SECRETARY, Tgrade of TECHNICIAN l Type inheritance: a subclass also inherits all attributes of its superclass –SECRETARY inherits the attributes Name, SSN, Birth_date and Address from the EMPLOYEE entity type (its superclass)

11 1 Relationships of a Subclass l A subclass can participate in specific relationship types –Ex: MANAGER subclass participates in the MANAGES relationship with PROJECT entity type

12 12 Relationships of a Subclass l A subclass also inherits all the relationships in which the superclass participates –If EMPLOYEE participates in WORKS_FOR relationship with DEPARTMENT then  SECRETARY also participates in WORKS_FOR relationship with DEPARTMENT  ENGINEER also participates in WORKS_FOR relationship with DEPARTMENT  TECHNICIAN also participates in WORKS_FOR relationship with DEPARTMENT  MANAGER also participates in WORKS_FOR relationship with DEPARTMENT  SALARIED_EMPLOYEE also participates in WORKS_FOR relationship with DEPARTMENT  HOURLY_EMPLOYEE also participates in WORKS_FOR relationship with DEPARTMENT

13 13 Constraints on Is-A Relationships l Constraint is defined on the subclass membership of the superclass entities –Disjointness constraint  How many subclasses a superclass entity can belong? (max) –Completeness constraint  Must a superclass entity belong to any of the subclasses? (min) Subclass1 Superclass Subclass2 Subclass3

14 14 Disjointness Constraint l Specifies whether subclasses are disjoint: –an entity can be a member of at most one of the subclasses of the specialization –Specified by “d” in EER diagram –Ex: STUDENT is either FRESHMAN, SOPHOMORE, JUNIOR, SENIOR, GRADUATE l If not disjoint, specialization is overlapping: –an entity may be a member of more than one subclasses –Specified by “o” in EER diagram –Ex: PERSON can be STUDENT, EMPLOYEE, or both do superclass

15 15 Completeness Constraint l Total specialization –Every entity in superclass must be a member of at least one subclass in the specialization –Ex: every EMPLOYEE must be either an HOURLY_EMPLOYEE or SALARIED_EMPLOYEE –Shown in EER diagrams by a double line l Partial specialization –Allows a superclass entity not to belong to any subclasses –Ex: some EMPLOYEE entities do not belong to any of the subclasses SECRETARY, TECHNICIAN, or ENGINEER –Shown in EER diagrams by a single line superclass

16 16 Example: Disjoint Partial Specialization Partial Disjoint

17 17 Example: Overlapping Total Specialization Total Overlapping

18 18 Exercise l Can a technician be an engineer? l Can a manager belong to a trade union?

19 19 Exercise: MOVIE database l Each movie is identified by title and year of release. Each movie has a length in minutes and is classified under one or more genres (horror, action, drama, etc) l Each movie has one or more directors and one or more actors appear in it. Each movie also has a plot outline and zero or more quotable quotes, each of which is spoken by a particular actor appearing in the movie l Actors are identified by name and date of birth and appear in one or more movies. Each actor has a role in the movie l Directors are also identified by name and date of birth and direct one or more movies. It is possible for a director to act in a movie (including one he or she may also direct)

20 20 Exercise: Movie Database ACTOR DIRECTOR MOVIE Title ID Year genres length DIRECTS ACTS Plot_ Outline role quotes N M M N Person Name ID DoB o

21 21 Hierarchies & Lattices l Hierarchy (Single Inheritance) –every subclass has only one immediate superclass l Lattice (Multiple inheritance) –a subclass can be subclass of more than one immediate superclass –A subclass with multiple immediate superclasses is called a shared subclass l In a lattice or hierarchy, a subclass inherits attributes not only of its immediate superclass, but also of all its predecessor superclasses

22 2 Lattice (Multiple Inheritance) Shared Subclass

23 23 Another Shared Subclass Example l ENGINEERING_MANAGER is a shared subclass –ENGINEERING_MANAGER Is-a ENGINEER –ENGINEERING_MANAGER Is-a MANAGER –ENGINEERING_MANAGER Is-a SALARIED_EMPLOYEE l It will inherit all the attributes of its superclasses, including EMPLOYEE, ENGINEER, MANAGER, and SALARIED_EMPLOYEE

24 24 Categories (UNION types) l A shared subclass is a subclass participating in multiple superclass/subclass (is-a) relationships –Each distinct relationship has a single superclass l In some cases, we need to model a single superclass/subclass relationship with more than one superclass –Each superclass can represent a different entity type –Such a subclass is called a category or UNION TYPE l Difference between shared subclass and union type –An entity of a shared subclass exists in all of its superclasses –An entity of a category exists in only one of its superclasses  It inherits only attributes of the superclass in which it belongs

25 25 Categories (UNION types) OWNER is the subclass of the union of 3 superclass entity types, PERSON,BANK, COMPANY (which have different key attributes)

26 26 Example of UNION types OWNER is the subclass of the union of 3 entity types, PERSON,BANK, COMPANY (which have different key attributes) REGISTERED_VEHICLE is the subclass of the union of CAR and TRUCK (which have same key attribute)

27 27 Constraints on UNION types l Total vs partial category (see example on next slide) –Total category holds the union of all entities in its superclasses  Represented by a double line –Partial category holds a subset of the union  Represented by a single line

28 28 Total vs Partial Category Registered User u User is the union of all registered and unregistered user entity types Owner is the union of all banks, but not all persons and not all companies Unregistered

29 29 Summary l Introduced the EER model concepts –Class/subclass relationships –Type inheritance –Shared subclass and categories (union types) l These augment the basic ER model concepts introduced in lectures 2-3


Download ppt "1 CSE 480: Database Systems Lecture 4: Enhanced Entity-Relationship Modeling Reference: Read Chapter 8.1 – 8.5 of the textbook."

Similar presentations


Ads by Google