Presentation is loading. Please wait.

Presentation is loading. Please wait.

--The Entity Relationship Model(2)--1 Reflexive Rela1tionships  An entity may be related to another entity of the same type.  Example: A Customer could.

Similar presentations


Presentation on theme: "--The Entity Relationship Model(2)--1 Reflexive Rela1tionships  An entity may be related to another entity of the same type.  Example: A Customer could."— Presentation transcript:

1 --The Entity Relationship Model(2)--1 Reflexive Rela1tionships  An entity may be related to another entity of the same type.  Example: A Customer could have Children, who are also Customers. Joe Doe is Jane Doe’s father. Bob Doe is Jane Doe’s son. Customer Joe Doe Bob Doe Jane Doe Sue San Child

2 --The Entity Relationship Model(2)--2 Reflexive Relationship Types - Diagram  Relationship type connects to self in an ER diagram. Children Customer

3 --The Entity Relationship Model(2)--3 Kinds of Relationship Types  How many of each entity type participate in a relationship type?  1-1  1-many  many-1  many-many  Total vs. Partial participation  Total participation means that every entity participates in the relationship.  Partial means that some entities might not participate.  Bounds (min-max) on participation  (At least) three different “diamond” notations  Arrow vs. straight line with or without participation bounds  DO NOT MIX NOTATIONS!

4 --The Entity Relationship Model(2)--4 An Example One-to-One Relationship Type  A Customer might be an Employee.  An Employee IsA Customer.  Participation is total on the Employee side in this example. CustomerIsAEmployee

5 --The Entity Relationship Model(2)--5 Diagramming One-To-One Rel. Types  An element in A is associated with at most one element in C via the relationship B. An element in C is associated with at most one element in A via B. A B C A B C A B C 11 (0,1)

6 --The Entity Relationship Model(2)--6 DVD Store Database Example  An employee can also be a customer.  Each Customer entity can be matched with at most one Employee entity, and each Employee entity can be matched with at most one Customer entity (both entities represent the same person).  Often this can be better represented using additional attributes, or by using subclasses (wait a few slides!) Employee IsA Customer 11

7 --The Entity Relationship Model(2)--7 Total vs. Partial Participation  Use a double line to indicate total participation.  Example: Every A is in a B relationship with exactly one C, but some C’s may be unrelated to an A.  Using participation constraints, total participation is a 1 on the minimum bound. A B C 11 A B C (1,1)(0,1)

8 --The Entity Relationship Model(2)--8 An Example One-to-Many Relationship Type  A Customer Rents zero to several DVD copies.  A DVD copy can be Rented by at most one Customer.  Participation is partial on both sides in this example. CustomerRentsDVD copy

9 --The Entity Relationship Model(2)--9 One-To-Many Relationship  An element in A is associated with several (including 0) elements in C via B. An element in C is associated with at most one element in A via B. A B C A B C A B C 1m (0,m)(0,1)

10 --The Entity Relationship Model(2)--10 DVD Store Database Example  A Customer might not be related to a DVD copy entity.  Each DVD copy entity is associated with at most one Customer entity. Customer Rents DVD copy 1m

11 --The Entity Relationship Model(2)--11 An Example Many-to-Many Rel. Type  A Performer Stars In one or many Films.  A Film can Star zero to many Performers.  Participation is total on the Performer in this example. PerformerStars InFilm

12 --The Entity Relationship Model(2)--12 Many-To-Many Relationship  An element in A is associated with several elements in C via B.  An element in C is associated with several elements in A via B. A B C A B C A B C nm (0,m)(0,n)

13 --The Entity Relationship Model(2)--13 DVD Store Database Example PerformerFilm mn Stars In NameFilmID Role

14 --The Entity Relationship Model(2)--14 Roles  Definition: A role is a label on a relationship type edge.  Example: labels "parent" and "child" are roles.  Roles are optional, and are used to clarify semantics of a relationship type. Children Customer (0,20) parent (0,2) child

15 --The Entity Relationship Model(2)--15 Weak Entity Types  Definition: A weak entity type borrows key attributes from another entity type (called the owning or strong entity type) to uniquely identify entities.  Example: A DVD copy has a Copy #, relative to a Film title (e.g., `Babe copy 1’, `Babe copy 2’, `Finding Nemo copy 1’. Copy # is not a key, but combined with Title it is (for DVD copy).  ER diagram - double box represents weak entity type.  The existence of a DVD copy entity depends on the existence of a Film entity. FilmDVD copy 1m Copies Status Copy # Title

16 --The Entity Relationship Model(2)--16 Weak Entity Type – Partial Keys  A weak entity type has a partial key (key is completed by borrowing key attributes from owning entity type(s)).  Example: Key for Video Tape is (Title, Copy#).  ER diagram - partial key represented with dashed line. FilmDVD copy 1m Copies Status Copy # Title

17 --The Entity Relationship Model(2)--17 Weak Entity Type, cont.  Semantics:  Deletion of a Film entity requires deletion of that film's DVD copy entities.  A weak entity is related to precisely one entity in the owning entity type, via a 1-1 or 1-many relationship.  It is possible to introduce more attributes to the DVD copy entity type, so that a primary key will exist, but they may not be needed for database processing.

18 18 Cascaded Weak Entity Types  Weak entity types can be cascaded:  Semantics:  To delete an employee, the family's dependents and their medical records must also be deleted. EmployeeDependent 1m emp fam Dependent Name Gender PhoneName SSN Fam med Medical Record Visit Num Date 1 m

19 A Video Store ER Schema Customer Rents DVD Status Film Copies Performer StarsIn Children Reserves NumCheckOuts AmountPaid ReturnDate Status Title Address Street City State CustomerIDTotalRes Name Role Name FilmID RentalPrice Distributor Kind Date Director parent (0,n) child (0,2) 1m m 1 n nm m CopyNum


Download ppt "--The Entity Relationship Model(2)--1 Reflexive Rela1tionships  An entity may be related to another entity of the same type.  Example: A Customer could."

Similar presentations


Ads by Google