What is cardinality in Databases?

Some Body picture Some Body · May 16, 2012 · Viewed 104.5k times · Source

I have been searching all over the internet but I couldn't seem to find an answer that I can understand.

So kindly, if somebody could explain to me with the help of examples what is cardinality in databases?

Thank you.

Answer

Oded picture Oded · May 16, 2012

A source of confusion may be the use of the word in two different contexts - data modelling and database query optimization.

In data modelling terms, cardinality is how one table relates to another.

  • 1-1 (one row in table A relates to one row in tableB)
  • 1-Many (one row in table A relates to many rows in tableB)
  • Many-Many (Many rows in table A relate to many rows in tableB)

There are also optional participation conditions to the above (where a row in one table doesn't have to relate to the other table at all).

See Wikipedia on Cardinality (data modelling).


When talking about database query optimization, cardinality refers to the data in a column of a table, specifically how many unique values are in it. This statistic helps with planning queries and optimizing the execution plans.

See Wikipedia on Cardinality (SQL statements).