One-to-Many Relationships in Tables

A one-to-many relationship allows several rows to reference one parent while each child row uses a single reference for that role.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a category
  2. Choose what multiplicity means
  3. Count children without duplicating parent information
  4. Avoid reversing the cardinality by accident

Trace a category

A category row can be referenced by three articles. Each article records its category ID under the chosen design. The foreign key controls valid referenced IDs.

Choose what multiplicity means

A category with no articles can exist if the domain permits it. A list can still show that category as an empty collection. Empty collections and missing records provide separate presentation outcomes.[1][2]

Count children without duplicating parent information

One library branch can have several shelf rows. Store the branch name once and let each shelf reference its branch. Changing the branch's description then updates one parent record. A branch with no shelves can still exist if the domain permits it. See foreign-key references.

Branch 1: Riverside
Shelves A and B both reference 1
Branch 2: Central, currently no shelves

Avoid reversing the cardinality by accident

Adding uniqueness to the shelf's branch ID would permit at most one shelf per branch. Omitting the foreign key can allow a shelf referencing a missing branch. Test a second shelf and an empty branch.

References

  1. PostgreSQL Global Development Group, Data Definition ↩
  2. PostgreSQL Global Development Group, SQL Language Tutorial ↩