Entities, relationships and cardinality

Name the facts in a domain, then distinguish one-to-one, one-to-many and many-to-many relationships with optional participation. Conceptual design and relational mapping · Databases.

A table can hold the right nouns and still describe the wrong relationship. Name the roles before you count the links.

Start with facts and roles

An entity is a thing or concept the domain treats as having its own identity: a learner, a course or an enrollment. An attribute describes an entity or a relationship occurrence, such as a learner’s display name, a course’s title or an enrollment timestamp. An attribute is not automatically a relationship. enrolled_at describes an enrollment event; it does not, by itself, say how many learners may join a course.

The first scene uses a small learning domain. It places Learner, Course and Enrollment beside the facts they own, then names the roles in the relationships. Start from the sentence the domain must support: a learner enrolls in a course. The sentence has two entity roles and one relationship; the enrollment may also own facts that belong to that association.

Facts, roles and allowed counts

Read the steps as text

  1. Learner, Course and Enrollment are distinct domain concepts. The stated domain permits each learner to enroll in many courses and each course to have many learners; owned facts are visible while relationship roles remain unnamed.
  2. Cardinality counts allowed related instances in each direction. One instructor can serve several courses, while each course names one instructor.
  3. The instructor-to-course rule is one-to-many. The profile relationship is one-to-one under its stated bounds.
  4. The learner-course rule is now shown in both directions: a learner may enroll in many courses and a course may have many learners. The enrollment role can own facts about each pairing.
  5. The profile rule is one-to-one at the relationship level: a learner has at most one profile and a profile belongs to at most one learner. That bound is separate from whether every learner must have a profile.
  6. The roles, directional counts and participation boundary are shown as separate domain rules: entities own facts, relationships connect roles, and cardinality answers how many.

Cardinality answers “how many?” for each direction. One learner may enroll in many courses, and one course may have many learners: that is many-to-many. One course may have one instructor while an instructor teaches many courses: that is one-to-many. A profile may belong to at most one learner, and a learner may have at most one profile: that is one-to-one. The same pair of entity names can have different cardinality when the relationship role changes, so always state the direction and the domain rule.

Ask whether participation is required

Cardinality and participation answer different questions. Cardinality says the maximum or allowed count. Participation says whether an instance may exist without this relationship. Every course may be required to have an instructor, making that participation mandatory. A learner may have no profile yet, making the profile relationship optional for the learner. A relationship can therefore be one-to-many and optional on one side, or one-to-one with optional participation on both sides.

The second scene changes the domain case without changing the vocabulary. A library Member can exist before borrowing, a Book can exist before its first loan, and a Loan must name exactly one member and one book. A member may have no locker, while every loan has both required participants. Read those as domain rules first. The later mapping lesson will decide where keys and association rows express them.

Optional and mandatory library links

Read the steps as text

  1. Library policy permits a Member record to exist before a Locker is assigned. The snapshot has Member M-17 with no Locker row; Loan L-42 names M-17 and B-9. Participation classification is withheld.
  2. The Member–Locker absence is now classified as optional. Library policy says every Loan MUST name exactly one Member and exactly one Book; L-42 is one example, and the result for those roles is pending.
  3. Every Loan names one Member and one Book, so both Loan roles are mandatory. The next comparison introduces owner-dependent identity and subtypes.
  4. A dependent LockerSlot has a branch owner and local discriminator, while a general Account has MemberAccount and StaffAccount subtypes. Both are bounded modeling extensions.
  5. Optionality and mandatory participation are separate from cardinality, while weak identity and specialization remain qualified modeling context.

A weak entity is a bounded extension of identity: a dependent LockerSlot may be identified only together with its library branch owner and a slot number that is unique within that branch. Specialization is another modeling choice: a general Account entity may have more specific subtypes such as MemberAccount and StaffAccount. These ideas help describe domains, but they do not force one universal relational mapping. Keep them as context until the mapping scene makes the chosen representation explicit.

Read a relationship as a sentence

The phrase “member borrows book through loan” gives the relationship its roles, but it does not yet say whether a member may have none, whether a book must have one, or whether a loan can omit either participant. Those are separate domain decisions. Write them as sentences: “a member may borrow many books,” “a book may have many loans,” and “a loan names exactly one member and one book.” A locker rule can say “a member may have zero or one locker.” The words zero, one and many expose assumptions that a table sketch can hide.

This also keeps attributes in the right place. A course title belongs to the course role; a learner name belongs to the learner role; enrolled_at belongs to the relationship event. If a fact changes when the pair changes, treat it as relationship-owned until the mapping review proves otherwise. The scene should show those ownership choices before any key or reference syntax appears.

Recap

  • Entities own facts; attributes describe them; relationships connect named roles between entity instances.
  • One-to-one, one-to-many and many-to-many describe allowed counts in each direction.
  • Optional and mandatory participation are separate from cardinality; weak entities and specialization are bounded modeling extensions.
Why the association can own facts

A relationship may have its own attributes. enrolled_at, status or a learner’s role in a course belongs to the enrollment association rather than to the learner or course alone. Treating that association as a first-class fact makes the domain sentence precise and gives the next lesson a clear object to map. It also prevents a many-to-many relationship from being hidden inside a list-valued attribute.

For a concrete identity connection, practise hash maps in Fundamentals: a map stores a key-to-value association, while a data model must state which domain entities and relationship roles that association represents.