1 of 25

ER Models

Relationships

2 of 25

Recall

  • Entity
  • Attribute
    • Domain
    • Simple
    • Composite
    • Multi-valued
    • Derived
    • Key

3 of 25

Relationship

  • More formally, a relationship-type
  • Represents an association between entities
    • Usually verbs
    • Use relationships, not attributes, to associate entities
    • Degree – how many entities are related (binary, ternary)
    • Represented by a diamond

works_at

CLINIC

DOCTOR

4 of 25

Relationship Constraints

  • Cardinality
    • How many instances of one entity relate to one instance of the other?
    • one or many
    • singular or plural (zybook terminology)
  • Participation
    • Does every instance of an entity participate in the relationship?
    • Total/mandatory/required or partial/optional

5 of 25

Cardinality

  • Possibilities:
    • 1-to-1
    • 1-to-many (1-to-N)
    • many-to-many (N-to-M)
  • Chen notation
    • put the numbers (1, N, M ) on each relationship line
  • Crow’s foot notation
    • crow’s foot on the N side, small line on the 1 side

6 of 25

Participation

  • Mandatory/total/required participation
    • Every instance of the entity must participate in the relationship
  • Partial/optional participation
    • There may be an instance of the entity that does not participate in the relationship
  • Chen – double line for total, single for partial
  • Crow’s foot – small line for total, small O for partial

7 of 25

Examples

8 of 25

Relationship Attributes

  • Relationships may have their own attributes
  • These attributes do not belong to either entity

9 of 25

MedEx Company (so far)

10 of 25

Group Activity: Abstract ER Part 1

11 of 25

Identifying Relationship – Weak Entity

  • A weak entity has no individual unique identity without its relationship to another entity
    • Does not exist without the identifying relationship
    • Partial key combined with identifying key form unique identifier

12 of 25

Identifying Relationship – Weak Entity

13 of 25

Legal

Illegal

14 of 25

Multiple Identifying Relationships

15 of 25

Ternary Relationships

  • Imagine that MedX company has partnership agreements with some pharmacies in the area
  • Assume the MedX clinic doctors can prescribe/order medication for a patient from a partner pharmacy so that the patient can just go and pick it up or maybe have it delivered to their home or to the clinic

16 of 25

Ternary Relationships cont.

  • This relationship is many-to-many in all directions:
    • One doctor can prescribe meds for one patient from different pharmacies
    • One doctor can prescribe meds from one pharmacy to different patients
    • One patient can be prescribed meds from one pharmacy by different doctors
    • One patient can be prescribed meds by one doctor from different pharmacies
    • One pharmacy can provide meds prescribed by one doctor to different patients
    • One pharmacy can provide meds to one patient that were prescribed by different doctors

17 of 25

A Ternary Relationship

  • Many-to-many in all directions
    • M-N-K (in order not to imply equality)

18 of 25

A Ternary Relationship

19 of 25

A ternary relationship as a weak entity

20 of 25

Appointment

  • What is it?
    • A relationship between doctor and patient, with another relationship to clinic
    • A ternary relationship (doctor, patient, clinic)
    • An entity with relationships to doctor, patient, and clinic
    • A weak entity identified by doctor
    • A weak entity identified by doctor and patient

21 of 25

Appointment represented as a ternary relationship with many attributes.

22 of 25

Appointment represented as a weak entity identified by both doctor and patient.

23 of 25

Appointment represented as a weak entity identified only by doctor. This interpretation allows for empty appointment “slots”.

24 of 25

Recursive Relationship

  • A relationship between an instance of one entity and another instance of the same entity
  • For example,
    • One employee may be the manager of zero or more other employees
    • Not every employee has a manager (top boss)

25 of 25

Group Activity: Abstract ER Part 2