Relationships & Cardinality
Relationships & Cardinality
Entities do not exist in isolation. A Patient books Appointments; a Product belongs to a Category; a Student enrolls in many Courses and each Course has many Students. The lines that connect entities in an ERD are called relationships, and the numbers — or symbols — that annotate those lines are called cardinality.
Getting cardinality right is one of the most consequential decisions in data modeling: it determines how tables are structured, which foreign keys exist, whether junction tables are needed, and ultimately how much data integrity the database can enforce automatically. This lesson covers all three relationship types and teaches you to read and draw them using the standard crow-foot notation.
What Is Cardinality?
Cardinality describes how many instances of entity B can be associated with one instance of entity A, and vice versa. Two values must always be stated for each end of a relationship line:
- Minimum cardinality — the fewest instances that must participate (0 = optional, 1 = mandatory).
- Maximum cardinality — the most instances that can participate (1 = one, many = unbounded).
In crow-foot notation, these two values are encoded as symbols drawn at each end of the relationship line:
- A vertical bar (|) means "exactly one" — mandatory.
- A circle (○) means "zero" — optional.
- A crow foot (fork) means "many" — one or more (or zero or more, combined with circle).
Diagram 1 — Crow-Foot Notation Legend
Before drawing any ERD, internalize these six symbols. The diagram below shows all the combinations you will encounter.
The Three Relationship Types
One-to-One (1:1)
In a one-to-one relationship, one instance of entity A is associated with at most one instance of entity B, and vice versa. True 1:1 relationships are relatively rare in business data models — they often indicate that the two entities could be merged into one table, or that the split is intentional for security, performance, or modular reasons.
Example: In a hospital system, each Patient has exactly one MedicalRecord and each MedicalRecord belongs to exactly one Patient. The records are split because medical record access has stricter security controls than basic patient demographics.
In crow-foot notation, a 1:1 is drawn with a double-bar at both ends: one and only one on each side. If the relationship is optional on one side (e.g., a patient may not yet have a medical record created), replace one pair of bars with a circle-and-bar.
One-to-Many (1:M)
A one-to-many relationship is the most common type in relational databases. One instance of entity A is associated with zero, one, or many instances of entity B, but each instance of B is associated with exactly one instance of A.
Examples:
- One
Customerplaces zero or manyOrders; eachOrderbelongs to exactly oneCustomer. - One
Doctorhas one or manyAppointments; eachAppointmentis assigned to exactly oneDoctor. - One
Categorycontains zero or manyProducts; eachProductbelongs to exactly oneCategory.
Implemented in SQL by placing a foreign key in the "many" table referencing the primary key of the "one" table. The crow-foot appears at the "many" end; the double-bar (or circle-bar for optional) appears at the "one" end.
Many-to-Many (M:N)
In a many-to-many relationship, one instance of A can relate to many instances of B, and one instance of B can relate to many instances of A.
Examples:
- One
Studentenrolls in manyCourses; oneCoursehas manyStudents. - One
Bookis written by manyAuthors; oneAuthorwrites manyBooks. - One
Ordercontains manyProducts; oneProductappears on manyOrders.
M:N relationships cannot be implemented directly in a relational database. They require a junction table (also called a bridge table or associative entity) that holds foreign keys to both sides and turns the M:N into two 1:M relationships. This is covered in depth in Lesson 6.
grade and an enrollment_date, those attributes belong on the junction table — which is itself a full entity.
Diagram 2 — All Three Relationship Types (Online Store)
The following ERD shows all three relationship types in a single model for a simplified online store. Read each relationship line using the legend above.
Reading the Diagram
Let us read each relationship in plain English to practice the notation:
- Customer — CustomerProfile (1:1): One
Customerhas exactly oneCustomerProfile. OneCustomerProfilebelongs to exactly oneCustomer. Neither side is optional here — both entities must exist together. - Customer — Order (1:M): One
Customermay place zero or manyOrders(optional many). EachOrdermust belong to exactly oneCustomer(mandatory one). A customer account can exist before any order is placed, which is why the Order end is "zero or many" not "one or many." - Order — OrderItem — Product (M:N resolved): One
Ordermust contain one or manyOrderItems. EachOrderItemreferences exactly oneOrder. Similarly, oneProductmay appear on one or manyOrderItems, and eachOrderItemrefers to exactly oneProduct. The M:N between Order and Product is resolved through theOrderItemjunction table, which also holds thequantityattribute that naturally belongs to the association.
NOT NULL foreign key constraint; an optional one allows NULL. Always ask both questions: "Can this be zero?" and "Can this be many?"
Diagram 3 — Library System: Verifying Your Reading
Here is a second ERD for a library management system. Study it and try to articulate each relationship in plain English before reading the description below.
Reading the library ERD:
- One
Membermay have zero or manyLoans(a new member has no loans yet). EachLoanbelongs to exactly oneMember. - One
BookCopymay appear on zero or manyLoansover its lifetime (a copy that was never borrowed has zero loans). EachLoancovers exactly oneBookCopy. - One
Bookhas one or many physicalBookCopies(a book title must have at least one copy to be in the system). EachBookCopybelongs to exactly oneBook.
Summary
- Cardinality specifies the minimum and maximum number of entity instances that participate in a relationship.
- Crow-foot notation encodes cardinality with three symbols at each line end: double-bar (exactly one), circle (zero / optional), and crow-foot fork (many).
- The three relationship types are 1:1 (rare, often a security or performance split), 1:M (the most common, implemented with a foreign key), and M:N (requires a junction table).
- Always state both minimum and maximum cardinality — the minimum determines whether the foreign key is nullable and whether the relationship is mandatory.
- When an M:N relationship has its own attributes (grade, quantity, enrollment_date), the junction table becomes a named associative entity in its own right.