1 / 19

Reflexive Rela 1 tionships

Reflexive Rela 1 tionships. 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. Child. Joe Doe. Jane Doe. Child. Sue San. Bob Doe. Customer.

joanna
Télécharger la présentation

Reflexive Rela 1 tionships

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Child Joe Doe Jane Doe Child Sue San Bob Doe Customer --The Entity Relationship Model(2)--

  2. Reflexive Relationship Types - Diagram • Relationship type connects to self in an ER diagram. Children Customer --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! --The Entity Relationship Model(2)--

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

  5. Diagramming One-To-One Rel. Types B • 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. (0,1) (0,1) A C B 1 1 A C B A C --The Entity Relationship Model(2)--

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

  7. Total vs. Partial Participation • Use a double line to indicate total participation. • Example: EveryAis in aBrelationship with exactly oneC, but someC’smay be unrelated to anA. • Using participation constraints, total participation is a 1 on the minimum bound. B 1 1 A C B (1,1) (0,1) A C --The Entity Relationship Model(2)--

  8. An Example One-to-Many Relationship Type • A CustomerRents 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. Customer Rents DVD copy --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. B (0,m) (0,1) A C B 1 m A C B A C --The Entity Relationship Model(2)--

  10. Rents 1 m Customer DVD copy 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. --The Entity Relationship Model(2)--

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

  12. Many-To-Many Relationship B • 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. (0,m) (0,n) A C B n m A C B A C --The Entity Relationship Model(2)--

  13. Name FilmID Stars In m n Performer Film Role DVD Store Database Example --The Entity Relationship Model(2)--

  14. (0,20) parent Children Customer (0,2) child 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. --The Entity Relationship Model(2)--

  15. Copy # Title Status Copies 1 m Film DVD copy Weak Entity Types • Definition: A weakentity 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 aDVD copyentity depends on the existence of aFilmentity. --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. Copy # Title Status Copies 1 m Film DVD copy --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. --The Entity Relationship Model(2)--

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

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

More Related