database 主键和主属性有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22064977/
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 the difference between Primary key and prime attribute?
提问by user3243499
Is there any difference between primary key (which is a composite key) and a prime attribute?
主键(复合键)和主属性之间有什么区别吗?
回答by SriniV
A candidate keyis a key that uniquely identifies rows in a table. Any of the identified candidate keys can be used as the table's primary key. Candidate keys that are not part of the primary key are called alternate keys. One can describe a candidate key as a super keythat contains only the minimum number of columns necessary to determine uniqueness.
候选键是唯一标识表中行的键。任何识别出的候选键都可以用作表的主键。不属于主键的候选键称为备用键。可以将候选键描述为仅包含确定唯一性所需的最少列数的超级键。
Prime attributesare the attributes of the candidate key which defines the uniqueness (Eg: SSN number in an employee database)
主要属性是定义唯一性的候选键的属性(例如:员工数据库中的 SSN 号)
A primary keyis a column in a table whose values uniquely identify the rows in the table. The primary key is chosen from this list of candidates based on its perceived value to the business as an identifier.
主键是表中的一列,其值唯一地标识表中的行。主键是根据其作为标识符对业务的感知价值从该候选列表中选择的。
A primary key value:
一个主键值:
- Must uniquely identify the row;
- cannot have NULL values;
- Should not change over the time;
- and Should be as short as possible.
- 必须唯一标识行;
- 不能有 NULL 值;
- 不应随时间变化;
- 并且应该尽可能短。
If the primary key is a combination of more than one column then it is called as composite key.
如果主键是多列的组合,则称为复合键。
回答by KRUKUSA
Primary keys may consist of a single attribute or multiple attributes in combination. For example
主键可以由单个属性或多个属性的组合组成。例如
name login email
Bob catlover [email protected]
Jason doglover [email protected]
The login would be the primary key and the attribute will be the catlover/doglover everything that is attributed in that key
登录名将是主键,属性将是 catlover/doglover 属于该键的所有内容
回答by Nafees Tariq
In order to understand the difference primary key and prime attributes, one should first know what is a super and candidate key.
为了理解主键和主要属性的区别,首先应该知道什么是超级键和候选键。
Super Key:Any attribute/combination of attributes whose closure, on the basis of given functional dependencies, determines the complete relation is a Super Key. (A relation could have more than one super keys)
超级键:任何属性/属性组合,其闭包,基于给定的函数依赖关系,确定完整的关系是超级键。(一个关系可以有多个超级键)
For example in relation R(A,B,C,D); given the functional dependencies as:
例如在关系 R(A,B,C,D) 中;给定函数依赖为:
ABC->D
ABC->D
AB->CD
AB->CD
A->BCD
A->BCD
D->ABC
D->ABC
Following are the super keys
以下是超级键
ABC; because its closure gives the complete relation i.e., (ABC)->ABCD
ABC; 因为它的闭包给出了完整的关系,即 (ABC)->ABCD
AB; because it's closer also gives the complete relation i.e., (AB)->ABCD
AB; 因为它更接近也给出了完整的关系,即 (AB)->ABCD
A; because it's closure also gives the complete relation i.e., (A)->ABCD
一种; 因为它的闭包也给出了完整的关系,即 (A)->ABCD
D; because it's closure also gives the complete relation i.e., (D)->ABCD
D; 因为它的闭包也给出了完整的关系,即 (D)->ABCD
Candidate Key:Any super key whose proper subset is not a super key is a Candidate Key.(A relation could have more than one candidate keys)
候选键:任何真子集不是超级键的超级键都是 候选键。(一个关系可以有多个候选键)
So, in the example above, Aand Dare the only candidate keys.
因此,在上面的示例中,A和D是唯一的候选键。
Primary Key:Any candidate key (may or may not be minimal) which is being chosen by the database designer to identify record is a Primary Key. (A relation can have only one primary key/(composite primary key: primary key that is made up of more than one columns))
主键:数据库设计者选择用于识别记录的任何候选键(可能是也可能不是最小的)都是主键。(一个关系只能有一个主键/(复合主键:由多列组成的主键))
In the example above, A(let's say)is the primary key.
在上面的例子中,A (假设)是主键。
Prime Attributes:An attribute that is present in any of the candidate keys is a prime attribute.
主要属性:存在于任何候选键中的属性是主要属性。
So, in the example above, Aand Dare prime attributes.
因此,在上面的示例中,A和D是主要属性。
回答by Nafees Tariq
Primary key:A primary key is a column (or combination of columns) designated to uniquely identify all records in the table.
主键:主键是指定用于唯一标识表中所有记录的列(或列的组合)。
Prime Attributes:Ideally all attributes with no incoming edge form set of prime attribute(s).
主要属性:理想情况下,所有属性都没有传入边形成主要属性集。
回答by Yuresh Karunanayake
Student_table {IndexNo,Name,ExamNo,Age,Class,City}
Student_table {IndexNo,Name,ExamNo,Age,Class,City}
- {IndexNo},{Name,ExamNo} are the candidates keys. From them I'ill choose {IndexNo} as the Primary Key.Those all indexNo,Name,ExamNo are prime attributes
- {IndexNo},{Name,ExamNo} 是候选键。从中我会选择 {IndexNo} 作为主键。所有的 indexNo,Name,ExamNo 都是主要属性
Employee_table {ID,Name,MobileNo,Age,Height}
Employee_table {ID,Name,MobileNo,Age,Height}
- {ID},{MobileNo} are the candidates keys. From them I'ill choose {ID} as the Primary Key.Those all ID,MobileNo attributes are prime attributes
- {ID},{MobileNo} 是候选键。从中我会选择 {ID} 作为主键。所有 ID、MobileNo 属性都是主要属性
Lets Look at the definitions. (Attributes mean columns)
让我们看看定义。(属性表示列)
Candidate key- Attributes or combination of attributes that can used to uniquely identify table records.
候选键- 可用于唯一标识表记录的属性或属性组合。
Prime key- Attribute that forms candidate keys.
主键- 形成候选键的属性。
Primary Key- A attribute from candidate keys, Than used to Uniquely identify the table records.It should Unique, Not Null, Should not update frequently.
主键- 候选键的一个属性,用于唯一标识表记录。它应该是唯一的,不是空的,不应该经常更新。

