Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE 480: Database Systems Lecture 8: EER to Relational Mapping and DBDesigner Reference: Read Chapter 9 of the textbook.

Similar presentations


Presentation on theme: "1 CSE 480: Database Systems Lecture 8: EER to Relational Mapping and DBDesigner Reference: Read Chapter 9 of the textbook."— Presentation transcript:

1 1 CSE 480: Database Systems Lecture 8: EER to Relational Mapping and DBDesigner Reference: Read Chapter 9 of the textbook

2 2 EER to Relation Mapping Mapping of superclass/subclass relationships Mapping of shared subclasses Mapping of union types (categories)

3 3 Mapping of Superclass/Subclasses Let R be the superclass {S 1, S 2,….,S m } are the subclasses –Each subclass can have its own local attributes R S1S1 S2S2 SmSm … k a1a1 a2a2 b1b1 b2b2 c

4 4 EER to Relation Mapping Step 8: 4 possible approaches –Option 8A: Multiple relations – Superclass and subclasses –Option 8B: Multiple relations – Subclass relations only –Option 8C: Single relation with one type attribute –Option 8D: Single relation with multiple type attributes

5 5 Mapping EER Constructs to Relations Option 8A: Multiple relations - superclass and subclass –Create superclass relation with attributes {k,a 1,a 2 } and primary key (PK) = k –Create a relation S i for each subclass S i, with attributes {k} U {attributes of S i } with PK = k. R S1S1 S2S2 SmSm … k a1a1 a2a2 b1b1 b2b2 c1c1 ka1a1 a2a2 R kc1c1 c2c2 SmSm c2c2 kb1b1 b2b2 S1S1 …

6 6 Example

7 7 MySQL Workbench Example Click on 1-1 identifying relationship type Click on subclass first before superclass. Repeat this for all 3 subclasses.

8 8 MySQL Workbench Example

9 9 Mapping EER Constructs to Relations Option 8B: Multiple relations –subclass relations only –Create a relation for each subclass S i, with the attributes of S i and the superclass –Works for total specialization (i.e., every entity in the superclass must belong to (at least) one of the subclasses) R S1S1 S2S2 SmSm … k a1a1 a2a2 b1b1 b2b2 c1c1 c2c2 a1a1 a2a2 kc1c1 c2c2 SmSm a1a1 a2a2 kb1b1 b2b2 S1S1 …

10 10 Example Tonnage Total specialization

11 1 Limitation of previous two approaches Query: What does John Doe do as an employee? To answer this query, we need to scan all three subclass relations, which is inefficient!

12 12 Option 8C: Single relation – with one type attribute (t) –Create a single relation with attributes {k,a 1,…a n } U {attributes of S 1 } U…U {attributes of S m } U {t} with primary key, PK = k –The attribute t is called a type (or discriminating) attribute –This option works for disjoint specialization EER to Relations Mapping d C S1S1 S2S2 SmSm … k a1a1 a2a2 b1b1 b2b2 c1c1 c2c2 t a1a1 a2a2 kb1b1 b2b2 R c1c1 c2c2 … t

13 13 Example EngType d

14 14 EER to Relations Mapping Option 8D: Single relation – with multiple type attributes –Create a single relation with attributes {k,a 1,…a n } U {attributes of S 1 } U…U {attributes of S m } U {t 1, t 2,…,t m } and PK = k –t i is a Boolean attribute indicating whether a tuple belongs to S i. –This option works for overlapping specialization o C S1S1 S2S2 SmSm … k a1a1 a2a2 b1b1 b2b2 c1c1 c2c2 a1a1 a2a2 kb1b1 b2b2 R c1c1 c2c2 …… t1t1 tmtm

15 15 Example

16 16 So which option is better? Depends on applications; must consider tradeoff: –Too many relations (options 8A and 8B)  Inefficient query processing –Single relation (options 8C and 8D)  Lots of nulls; may “lose” some meaningful relationships If everything is mapped to the Employee relation, we lose the relationship between hourly employee and trade union

17 17 EER to Relations Mapping Mapping of Shared Subclasses (Multiple Inheritance) –A shared subclass is a subclass of several superclasses, indicating multiple inheritance.  These superclasses must have the same key attribute –Can apply any of the four options (subject to their restrictions – total/partial, overlapping/disjoint)

18 18 o Example STUDENT_ASSISTANT is a shared subclass of the EMPLOYEE and STUDENT entity types

19 19 Example Since there are usually separate queries for employees, alumni, and students, we can use options 8A or 8B –Relations for option 8A: Person, Employee, Alumnus, Student –Relations for option 8B: Employee, Alumnus, Student

20 20 Example o Suppose we want to use option 8C and 8D to group all employees into a single relation called EMPLOYEE

21 21 Example o Suppose we want to use option 8C to group all students into a single relation called STUDENT

22 2 Putting it all together…

23 23 Union Types (Categories) Superclass can have several keys How to deal with OWNER? Add owner_type

24 24 Mapping of Union Types (Categories) If all the superclasses have the same key –Include the key as an attribute of the category Otherwise –Create a new key attribute, called a surrogate key, as primary key of the category –Add surrogate key as foreign key for each superclass relation of the category –Add an attribute type to the category identifying particular entity type of the superclasses (PERSON, BANK, COMPANY)

25 25 Example (Owner Entity Type) Owner_id is surrogate key

26 26 Example (Registered_Vehicle)

27 27 Example

28 28 Exercise: Art Museum Database


Download ppt "1 CSE 480: Database Systems Lecture 8: EER to Relational Mapping and DBDesigner Reference: Read Chapter 9 of the textbook."

Similar presentations


Ads by Google