database 什么是数据库中的基数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10621077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is cardinality in Databases?
提问by Some Body
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.
谢谢你。
回答by Oded
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)
- 1-1(表A中的一行与表B中的一行相关)
- 1-Many(表A中的一行与表B中的多行相关)
- 多对多(表 A 中的多行与表 B 中的多行相关)
There are also optional participation conditions to the above (where a row in one table doesn't haveto 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).
请参阅关于基数(SQL 语句)的维基百科。
回答by Justin Cave
It depends a bit on context. Cardinality means the number of something but it gets used in a variety of contexts.
这有点取决于上下文。基数意味着某物的数量,但它在各种上下文中得到使用。
- When you're building a data model, cardinality often refers to the number of rows in table A that relate to table B. That is, are there 1 row in B for every row in A (1:1), are there N rows in B for every row in A (1:N), are there M rows in B for every N rows in A (N:M), etc.
- When you are looking at things like whether it would be more efficient to use a b*-tree index or a bitmap index or how selective a predicate is, cardinality refers to the number of distinct values in a particular column. If you have a
PERSONtable, for example,GENDERis likely to be a very low cardinality column (there are probably only two values inGENDER) whilePERSON_IDis likely to be a very high cardinality column (every row will have a different value). - When you are looking at query plans, cardinality refers to the number of rows that are expected to be returned from a particular operation.
- 在构建数据模型时,基数通常是指表 A 中与表 B 相关的行数。也就是说,对于 A 中的每一行,B 中是否有 1 行 (1:1),是否有 N 行在 B 中对于 A 中的每一行(1:N),对于 A 中的每 N 行,B 中是否有 M 行(N:M),等等。
- 当您考虑使用 ab*-tree 索引或位图索引是否更有效或谓词的选择性如何时,基数是指特定列中不同值的数量。
PERSON例如,如果您有一个表,GENDER它很可能是一个非常低的基数列(可能只有两个值GENDER),而PERSON_ID可能是一个非常高的基数列(每一行都有不同的值)。 - 在查看查询计划时,基数是指预期从特定操作返回的行数。
There are probably other situations where people talk about cardinality using a different context and mean something else.
可能还有其他情况,人们使用不同的上下文谈论基数并表示其他含义。
回答by Premraj
In database, Cardinalitynumber of rows in the table.
在数据库中,表中的基数行数。
- Relationships are named and classified by their cardinality(i.e. number of elements of the set).
- Symbols which appears closes to the entity is Maximum cardinalityand the other one is Minimum cardinality.
- Entity relation, shows end of the relationship lineas follows:

- 关系按其基数(即集合的元素数)命名和分类。
- 出现在实体附近的符号是最大基数,另一个是最小基数。
- 实体关系,显示关系线的结尾如下:

image source
图片来源
回答by Andrew
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.
基数是指列中包含的数据的唯一性。如果一列有大量重复数据(例如,存储“true”或“false”的列),则其基数较低,但如果值高度唯一(例如社会安全号码),则基数较高。
回答by user2923871
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
集合的基数是集合中元素的数量,因为我们有一个集合 a > a,b,c < 所以这个集合包含 3 个元素 3 是该集合的基数
回答by kta
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.
当你定义对象之间的基数时,你必须考虑所有这些事情来定义正确的基数。

