Cardinality
Cardinality
Definition
The cardinality of a relation is the number of tuples (rows) it currently contains. Unlike degree, cardinality is a property of the INSTANCE (the data), not the schema — so it is inherently dynamic, changing with every successful INSERT or DELETE.
Example
If Students currently holds tuples for Asha, Ravi, Meera, and Karan, its cardinality is 4. After a 5th student, Priya, is admitted, cardinality becomes 5 — with absolutely no change to the schema or the degree (still 4 attributes).
How this differs from Degree (its closest sibling)
- Cardinality = number of rows = instance-level = changes constantly.
- Degree = number of columns = schema-level = fixed until a schema migration.
A relation can have cardinality 0 (an empty table, e.g., right after CREATE TABLE) while still having a well-defined, non-zero degree — the two quantities are completely independent of each other.
Cardinality of a relation should also not be confused with "cardinality" in the ER-diagram / relationship sense (one-to-many, many-to-many). That is a different, related use of the same word, describing relationship multiplicity between entity sets — not a row count of a relation.
Edge Cases
- Cardinality 0 is valid and common — a freshly created or fully truncated table.
- Bulk operations (
TRUNCATE, batch inserts) can change cardinality drastically in a single step, without any schema change whatsoever. - Because a relation is a SET, inserting a tuple that is an exact duplicate of an existing one does not increase cardinality in the pure mathematical model — though in practice, SQL without a uniqueness constraint would physically add the duplicate row and increase the row count, which is one place SQL tables deviate from strict relation semantics.
Key Takeaways / Q&A
Q: A table starts with 100 rows; after some deletes and inserts it has 87 rows. What changed — degree, cardinality, or both? A: Only cardinality — degree is untouched unless columns were added or removed.
Q: Can cardinality exceed the size of the Cartesian product of the attribute domains? A: No — cardinality is bounded above by |D1| × |D2| × ... × |Dn|, since a relation is, by definition, a subset of that Cartesian product.