Chapter 03 · Relationships, Cardinality, and Participation

Recursive, Ternary, and Higher-Order Relationships

Model recursive, ternary, and higher-order relationships without losing role semantics or incorrectly decomposing relationships whose meaning depends on all participants.

Beginner55–75 minutesAdvanced ER modelingLast reviewed: August 2026

Learning outcomes

Binary relationships between different entity types cover much of everyday database design, but not all of it. Real domains include self-references, relationships that depend on three participants together, and occasionally higher-order associations. Modeling these structures correctly requires role clarity and careful testing before decomposition.

01

Model recursive relationships with explicit role names.

02

Distinguish a true ternary relationship from three independent binary relationships.

03

Recognize information loss caused by incorrect decomposition.

04

Map recursive and ternary relationships into relational structures.

Recursive relationships

A recursive or unary relationship occurs when an entity type relates to itself in different roles. Examples include:

  • Employee supervises Employee;
  • Category contains Category;
  • Part is assembled from Part;
  • Account transfers funds to Account.

The roles are essential because both relationship ends use the same entity type.

One-to-many recursive relationship

Suppose each technician may have one mentor while a mentor can support many technicians:

model · example
Technician  technician_id  mentor_technician_id -> Technician.technician_id

This is a recursive one-to-many relationship. Role names are:

  • mentor — referenced technician;
  • mentee — technician holding the foreign key.
sql · example
CREATE TABLE technician (    technician_id        INTEGER PRIMARY KEY,    full_name            TEXT NOT NULL,    mentor_technician_id INTEGER,    FOREIGN KEY (mentor_technician_id)      REFERENCES technician(technician_id),    CHECK (mentor_technician_id IS NULL           OR mentor_technician_id <> technician_id));

The self-reference can prevent direct self-mentoring, but preventing longer cycles may require more advanced logic.

Recursive many-to-many relationship

Suppose parts can substitute for other parts and substitution may be many-to-many. A separate associative relation is appropriate:

model · example
PartSubstitution(  original_part_id    -> Part  substitute_part_id  -> Part  approved_at  reason)

Role names original and substitute prevent ambiguity.

Hierarchies are recursive relationships with additional rules

Category parentage may look simple:

model · example
Category.parent_category_id -> Category.category_id

But a hierarchy may need rules such as:

  • no category can be its own ancestor;
  • maximum depth is limited;
  • one parent versus multiple parents;
  • moving a subtree must remain atomic;
  • paths and descendants must be queried efficiently.

Chapter 14 returns to recursive structures and alternative hierarchy representations.

Ternary relationships

A ternary relationship represents a fact whose meaning depends jointly on three entity types. Consider:

Supplier supplies Part to Warehouse at an agreed price.

The fact is not simply that Supplier supplies Part, Supplier works with Warehouse, and Warehouse stores Part. The agreed price may depend on the exact triple:

model · example
(supplier_id, part_id, warehouse_id) -> agreed_price

Why three binary relationships may lose meaning

Suppose we decompose the ternary fact into:

  • Supplier–Part;
  • Supplier–Warehouse;
  • Part–Warehouse.

Knowing all three pairwise relationships does not tell us which supplier supplies which part to which warehouse under one agreement. The combinations can be recombined incorrectly.

Decomposition test

If the business fact or its attributes depend on the combination of all participants, do not decompose it merely to avoid a ternary relationship.

Relational mapping of a ternary relationship

sql · example
CREATE TABLE supply_agreement (    supplier_id   INTEGER NOT NULL,    part_id       INTEGER NOT NULL,    warehouse_id  INTEGER NOT NULL,    agreed_price  NUMERIC NOT NULL,    currency_code TEXT NOT NULL,    lead_days     INTEGER,    PRIMARY KEY (supplier_id, part_id, warehouse_id),    FOREIGN KEY (supplier_id) REFERENCES supplier(supplier_id),    FOREIGN KEY (part_id) REFERENCES part(part_id),    FOREIGN KEY (warehouse_id) REFERENCES warehouse(warehouse_id));

The composite key is one possible choice. A surrogate agreement ID may also be useful if agreements have their own lifecycle, versions, documents, or references.

When a ternary relationship can be decomposed

Decomposition is valid when the domain actually contains independent binary facts and no important information is lost. For example, if Supplier is approved separately for Part, Warehouse stocks Part separately, and Supplier serves Warehouse separately—with no joint facts depending on all three—then three binary relationships may be correct.

The deciding factor is semantics, not diagram simplicity.

Higher-order relationships

Relationships of degree four or higher are possible, but they deserve careful review. Often one participant is actually:

  • an attribute;
  • a role;
  • a reference value;
  • a separate event/entity that can simplify the model.

For example, “Doctor prescribes Drug to Patient at Clinic” might be better represented as a Prescription entity connected to Doctor, Patient, Drug, and Clinic. The event/entity provides identity, time, dose, status, and auditability.

Promote complex relationships to entities when they have lifecycle

A ternary or n-ary association often becomes easier to manage when represented as an entity if it has:

  • its own identifier;
  • status transitions;
  • effective dates;
  • approval history;
  • documents or notes;
  • references from other entities.

This does not change the underlying semantic fact; it makes the association first-class.

WorkshopHub example: technician, task, and role

Suppose later WorkshopHub adds RepairTask. One possible fact is:

“A Technician performs a RepairTask in a specific AssignmentRole.”

If AssignmentRole is simply a controlled attribute on TaskAssignment, the model may remain binary between Technician and RepairTask. If roles are first-class governed entities and one assignment can carry several roles, the structure changes. This illustrates why apparent relationship degree depends on how concepts are modeled.

Practice: preserve the fact

Ternary test

A university records which Instructor teaches which Course in which Semester, including room and workload percentage.

  1. Can three pairwise relationships reproduce the complete teaching assignment?
  2. Which attributes belong to the combined assignment?
  3. Would you keep a ternary relationship or promote it to a TeachingAssignment entity?
Review guidance

Pairwise Instructor–Course, Course–Semester, and Instructor–Semester facts cannot identify the exact teaching combination. Room, workload percentage, and perhaps section belong to the combined assignment. A TeachingAssignment entity with instructor_id, course/section_id, semester_id, room, and workload is usually clearer and easier to reference.

Summary and next lesson

Recursive relationships use one entity type in multiple roles; ternary and higher-order relationships express facts that depend jointly on several participants. Decompose only when the business meaning survives. The next lesson returns to the most common complex case—many-to-many—and shows how to resolve it systematically into associative entities.

References

  • Ramez Elmasri and Shamkant B. Navathe, Fundamentals of Database Systems.
  • Peter P. Chen, “The Entity-Relationship Model—Toward a Unified View of Data,” 1976.
  • Thomas Connolly and Carolyn Begg, Database Systems.

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only assets compatible with the Ethereum/ERC-20 network. Do not send TRC-20/TRON assets.