Reputation: 2031
Could somebody explain to me, with the help of examples, what is cardinality in databases?
Upvotes: 122
Views: 153348
Reputation: 74631
In database, Cardinality number of rows in the table.
image source
Upvotes: 14
Reputation: 20130
Definition: We have tables in database. In relational database, we have relations among the tables. These relations can be one-to-one, one-to-many or many-to-many. These relations are called 'cardinality'.
Significant of cardinality:
Many relational databases have been designed following stick business rules.When you design the database we define the cardinality based on the business rules. But every objects has its own nature as well.
When you define cardinality among object you have to consider all these things to define the correct cardinality.
Upvotes: -2
Reputation: 1
Cardinality of a set is the namber of the elements in set for we have a set a > a,b,c < so ths set contain 3 elements 3 is the cardinality of that set
Upvotes: -2
Reputation: 231761
It depends a bit on context. Cardinality means the number of something but it gets used in a variety of contexts.
PERSON
table, for example, GENDER
is likely to be a very low cardinality column (there are probably only two values in GENDER
) while PERSON_ID
is likely to be a very high cardinality column (every row will have a different value).There are probably other situations where people talk about cardinality using a different context and mean something else.
Upvotes: 38
Reputation: 499142
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.
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).
Upvotes: 184
Reputation: 2164
Cardinality refers to the uniqueness of data contained in a column. If a column has a lot of duplicate data (e.g. a column that stores either "true" or "false"), it has low cardinality, but if the values are highly unique (e.g. Social Security numbers), it has high cardinality.
Upvotes: 10