liveBook · Manning

Cardinality

As explained in Grokking Relational Database Design

Cardinality is the number of instances of a target entity that can be associated with one instance of a source entity in a directional relationship.

Cardinality describes how many instances of one entity may be associated with one instance of another entity through a relationship. It turns requirements such as “a user can write reviews” into clear rules for an E-R diagram and, later, for foreign keys in database tables. section 5.4 section 5.10

Read cardinality in a direction. Given a relationship from entity A to entity B, cardinality answers: for one A, how many B instances are allowed? A user and an account illustrate both directions: a user may have zero, one, or many accounts, while an account belongs to one and only one user. section 5.5

Use the notation guide to recognize the symbols for zero, one, and many before combining them on a relationship line. section 5.5

For each directional relationship, record two limits:

  • Minimum cardinality: the fewest related instances required. A minimum of zero means the relationship is optional; one means a related instance is required. section 5.5
  • Maximum cardinality: the most related instances allowed. The common values are one and many. section 5.5
  • Place the paired symbols near the target entity—the B side when reading from A to B. section 5.5

Crow’s Foot notation represents these limits with paired symbols. It is used here rather than Chen notation because it is simpler and commonly used by professionals. Classifying both directions produces one of three relationship forms: one-to-one, one-to-many, or many-to-many. section 5.5 section 5.10

User and review: one-to-many

Start with two requirement sentences: “A user can write zero to many reviews” and “A review can be written by one and only one user.” The user-to-review direction has a zero-to-many range; the review-to-user direction is exactly one. This is one-to-many, so the review table—the many side—stores the user primary key as its foreign key. section 5.7

Use these implementation rules after identifying the relationship type:

  • For one-to-one, both maximum cardinalities are one. If both minimums are one, relax one minimum to zero so records can be inserted without circular foreign-key problems; the zero minimum can guide foreign-key placement. section 5.6
  • For one-to-many, put the foreign key on the many side, marked by the crow’s foot. One row on the one side can then relate to multiple rows on the many side. section 5.7
  • For many-to-many, create a junction table containing the primary keys of both entities, converting the relationship into two one-to-many relationships. section 5.10

A practical workflow is to write requirement sentences in both directions, find each direction’s minimum and maximum, draw the paired Crow’s Foot symbols, name the resulting relationship type, and then place foreign keys or add a junction table as required. section 5.4 section 5.10

How Grokking Relational Database Design covers it

How deep it goes
Explains directional minimum and maximum limits, notation, three relationship types, and implementation consequences including insertion constraints.
Examples
Uses user-account, department-manager, and user-review relationships to derive cardinalities and table links.
What it assumes
Teaches cardinality from requirement sentences while assuming identified entities and relationships for an E-R diagram.
What you can do after
Apply it to classify entity relationships, draw Crow’s Foot limits, and place foreign keys or junction tables.
How it connects
Connects relationships, E-R diagrams, Crow’s Foot notation, foreign keys, primary keys, junction tables, and weak entities.

Also explained in

Compare how 8 books explain cardinality →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.