Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is cardinality in Databases?

Could somebody explain to me, with the help of examples, what is cardinality in databases?

like image 966
Some Body Avatar asked May 16 '12 14:05

Some Body


People also ask

What is meant by cardinality in database?

In a database, cardinality usually represents the relationship between the data in two different tables by highlighting how many times a specific entity occurs compared to another. For example, the database of an auto repair shop may show that a mechanic works with multiple customers every day.

What is cardinality with example?

Cardinality refers to the number that is obtained after counting something. Thus, the cardinality of a set is the number of elements in it. For example, the set {1, 2, 3, 4, 5} has cardinality five which is more than the cardinality of {1, 2, 3} which is three.

What is cardinality explain?

The term cardinality refers to the number of cardinal (basic) members in a set. Cardinality can be finite (a non-negative integer) or infinite. For example, the cardinality of the set of people in the United States is approximately 270,000,000; the cardinality of the set of integers is denumerably infinite.

What is cardinality and why is it important?

Cardinality is a vital piece of information of a relation between two entites. You need them for later models when the actual table architecture is being modelled. Without knowing the relationship cardinality, one cannot model the tables and key restriction between them.


1 Answers

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).

like image 65
Oded Avatar answered Sep 21 '22 21:09

Oded