In Database Management Systems (DBMS), cardinality refers to the number of elements in a set or the number of relationships between entities in a database. There are a few contexts in which cardinality is important:
- Cardinality of a Table (Rows):
This refers to the number of rows (or records) in a table. For example, if a table has 100 rows, its cardinality is 100. - Cardinality of Relationships (between Tables):
This is related to how tables in a database relate to each other. Cardinality can define the type of relationship between two tables, and it can be:- One-to-One (1:1): A single row in one table is related to a single row in another table.
- One-to-Many (1:M): A single row in one table is related to multiple rows in another table.
- Many-to-Many (M:M): Multiple rows in one table are related to multiple rows in another table.
- Cardinality in Queries (Set Operations):
In the context of relational queries, cardinality can refer to the number of distinct results that a query returns. For instance, when usingSELECT DISTINCT
, you can get a sense of the cardinality of the result set.