Cardinality in DBMS
Press Next → or use ← → arrow keys
The Story — The Wedding Seating Question
The cardinality of a relationship is the actual number of related occurrences for each of the two entities. The ER diagram marks that count directly on the edges connecting entities to the relationship.
Get cardinality wrong and your tables either store impossible data or reject valid data.
Two (Really Three) Ideas Hidden in One Word
Connectivity answers "one or many?" · Cardinality answers "how many, at least and at most?" · Participation answers "is taking part compulsory?"
Connectivity — The Four Mapping Types
Each side is either "one" or "many," giving exactly four patterns. M:1 is the same relationship as 1:M, simply read from the opposite direction.
One-to-Many in Action — Customer & Loan
Pick one customer, count its loans: C1 has two → the loan side is "many". Pick one loan, count its customers: L1 has one → the customer side is "one". Confirmed 1:M — and C3 with no loan shows the customer's participation is optional.
Many-to-Many in Action — Supplier & Part
A supplier supplies many parts, and a part comes from many suppliers. There is nowhere to store QTY in the Supplier table or the Part table — it depends on the pair. QTY is an attribute of the link itself.
Cardinality Notation — The l..h Range
| l..h | Min | Max | Meaning |
|---|---|---|---|
| 1..1 | 1 | 1 | Exactly one — mandatory & single |
| 0..1 | 0 | 1 | At most one — optional, single |
| 1..* | 1 | many | At least one — mandatory, many |
| 0..* | 0 | many | Any number — optional, many |
Connectivity vs Cardinality — Side by Side
Values: only "one" or "many".
Types: 1:1, 1:M, M:1, M:M.
Answers: "What shape is the link?"
Expression: a precise range.
Notation: l..h (min..max) on an edge.
Answers: "How many, at least and at most?"
"One-to-many" is the headline; the ranges make it precise: the "one" side is 1..1 and the "many" side is 0..*. Connectivity is the shape; cardinality is the exact count.
Cardinality & Participation — Single vs Double Line
The minimum of l..h decides participation: min = 1 → total (double line, mandatory); min = 0 → partial (single line, optional). Cardinality (count) and participation are separate decisions, but both come from the same l..h.
How Cardinality Shapes Your Tables
A foreign-key column holds one value per row — so it can represent "many on one side" but never "many on both". That single fact is why M:M always needs a junction table.
Cardinality → SQL
1:M — the FK lives on the many side; M:M — a junction table holds the pair.
-- 1 : M → foreign key on the "many" (LOAN) side
CREATE TABLE CUSTOMER ( Cust_ID PRIMARY KEY, Name, City );
CREATE TABLE LOAN (
Loan_No PRIMARY KEY,
Amount,
Cust_ID REFERENCES CUSTOMER(Cust_ID) -- FK repeats freely
);
-- M : M → junction table holds both keys + the link attribute
CREATE TABLE SUPPLIER ( SNo PRIMARY KEY, Name );
CREATE TABLE PART ( PNo PRIMARY KEY, PName );
CREATE TABLE SUPPLIES (
SNo REFERENCES SUPPLIER(SNo),
PNo REFERENCES PART(PNo),
QTY, -- belongs to the pair
PRIMARY KEY (SNo, PNo)
);
SUPPLIES stores exactly one row per (supplier, part) pair, with QTY attached — the only place QTY can honestly live.
Three Common Mistakes to Avoid
Unsure of a pattern? Take real sample rows, pick one instance on each side, and count its partners. Two counts reveal whether it's 1:1, 1:M, M:1, or M:M.
Connectivity → Table Mapping
| Connectivity | "One" side l..h | "Many" side l..h | Maps to | Example |
|---|---|---|---|---|
| 1:1 | 0..1 / 1..1 | 0..1 / 1..1 | FK on either side | Person – Passport |
| 1:M | 1..1 | 0..* | FK on many side | Customer – Loan |
| M:1 | 0..* | 1..1 | FK on many side | Employee – Dept |
| M:M | 0..* | 0..* | Junction table | Supplier – Part |
| Symbol / Label | Means |
|---|---|
| 1 beside edge | The "one" side of connectivity |
| M or * | The "many" side of connectivity |
| l..h | Minimum (l) and maximum (h) cardinality |
| Single line | Partial participation (min = 0) |
| Double line | Total participation (min = 1, i.e. 1..*) |
Golden Rules of Cardinality — 1 to 3
Golden Rules of Cardinality — 4 to 6
Cardinality is where a business rule becomes a table shape. Ask the stakeholder "how many?" and "is it required?", write l..h, and the foreign keys and junction tables follow automatically.
Cardinality, Complete
You can now name the four connectivity patterns, write exact l..h ranges, read participation from the minimum, and turn any cardinality into the right tables — a foreign key for 1:M, a junction table for M:M. Next comes shaping those tables well: keys, functional dependencies and normalization.
The maximum tells you the shape (one or many); the minimum tells you if it's mandatory — and M:M always needs a table of its own.
🔢 End of tutorial · Press ← to review, or click Restart