Relationships & Cardinality

Lecture 3 · how entities connect, how many can connect, whether they must, and the special case of weak entities.

Relationship sets

  • A relationship is an association among entities; a relationship set is a set of such associations (e.g. advisor between instructor and student).
  • Relationships can carry descriptive attributes — e.g. date on advisor, grade on enrolls.
  • Degree = number of entity sets involved: binary (2, most common) or ternary (3).
  • Role = the function an entity plays — vital in recursive relationships where one entity set appears twice (course ↔ prerequisite, teacher ↔ mentor).

Mapping cardinality — the four shapes

1 : 1AB11Person–Passport1 : NAB1NDept–EmployeeN : 1ABN1Student–AdvisorN : NABMNStudent–Course
TypeMeaningExample
1 : 1Each A ↔ at most one B, and vice-versaPerson ↔ Passport
1 : NOne A ↔ many B; each B ↔ at most one ADepartment ↔ Employees
N : 1Many A ↔ one BStudents ↔ Advisor
N : NMany both waysStudents ↔ Courses

Participation

TypeLineMeaningExample
Totaldouble lineEvery entity must participateEvery student must have an advisor
Partialsingle lineSome entities may not participateSome instructors advise nobody
Complex constraint notation: a line labelled l..h gives min..max — 0..* = optional, many; 1..1 = exactly one. Min of 1 ⇒ total participation.

Weak entity sets

A weak entity can't be identified by its own attributes — it depends on an identifying (owner) entity. Its key uses a discriminator (partial key).
PK(weak) = PK(owner) + discriminator.

Example: course-offering / section is weak on course. Its PK is (course_id, sec_id, semester, year) — it borrows course_id from its owner.

  • Weak entity → double rectangle.
  • Identifying relationship → double diamond.
  • Discriminator → dashed underline.