主键,唯一键和候选键之间的区别

时间:2022-09-16 09:56:16

What is difference between Primary Key, Unique Key and candidate key?

主键,唯一键和候选键之间有什么区别?

7 个解决方案

#1


9  

Candidate key is a minimal (i.e. irreducible) key, unique key is a pleonasm, and primary key is an obsoleted concept still surviving from the days when people thought it possible for one key to be "more unique" than any of the others.

候选密钥是最小的(即不可简化的)密钥,唯一密钥是一个多余的密钥,而主键是一种过时的概念,当人们认为一个密钥可能比其他任何密钥“更独特”时,它仍然存在。

#2


13  

Super Key is the set of one or more column (ie attributes) which uniquely identifies a record.

超级密钥是唯一标识记录的一个或多个列(即属性)的集合。

Candidate key is a minimal Super key.(it mean we cant remove any attributes from it otherwise it will not remain Superkey anymore).

候选键是一个最小的超级键。(这意味着我们无法从中删除任何属性,否则它将不再保留超级键)。

Primary Key is a arbitrary selected Candidate key. There must be only and only One primary key. We can choose any candidate key as a Primary key. Other candidate keys which are not chosen as Primary are called Alternate Keys.

主键是任意选择的候选键。必须只有一个主键。我们可以选择任何候选键作为主键。未被选为主要的其他候选键称为备用键。

If Primary Key have more then one column (or attributes) ,it is called Composite Key.

如果主键有多个列(或属性),则称为复合键。

#3


4  

Google does not work anymore?

谷歌不再工作了?

http://en.wikipedia.org/wiki/Candidate_key

http://en.wikipedia.org/wiki/Candidate_key

http://en.wikipedia.org/wiki/Unique_key

http://en.wikipedia.org/wiki/Unique_key

#4


4  

Candidate keys - It is a column that can uniquely identify all columns for a specific row or instance of your database table. Your passport ID is a good example of a Candidate key and when using this ID you can retrieve a persons name, surname and other details related to that specific person.

候选键 - 它是一个列,可以唯一标识数据库表的特定行或实例的所有列。您的护照ID是候选密钥的一个很好的示例,使用此ID时,您可以检索与该特定人员相关的人员姓名和其他详细信息。

Primary key - There may be a few Candidate keys on a specific database table which is unique and can be used to identify a specific instance in a table e.g. Vehicle registration number, Chassis number, engine serial number etc... but remember there can only be one candidate key that will be used as a primary key. Difference between Candidate Key vs Primary Key:- ) Both Primary and Candidate keys can uniquely identify records in a table on database.

主键 - 特定数据库表上可能有一些候选键是唯一的,可用于标识表中的特定实例,例如车辆登记号,底盘号,发动机序列号等......但请记住,只能有一个候选钥匙用作主钥匙。候选密钥与主密钥之间的区别: - )主密钥和候选密钥都可以唯一地标识数据库中表中的记录。

2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.

2)主键和候选键都具有UNIQUE和NOT NULL约束。

3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.

3)主键或候选键可以是表中的单列或多列的组合。

#5


3  

Candidate Key – A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.

候选键 - 候选键可以是任何列或列的组合,可以作为数据库中的唯一键。一个表中可以有多个候选键。每个候选人密钥都可以作为主要密钥。

Primary Key – A Primary Key is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key. One needs to be very careful in selecting the Primary Key as an incorrect selection can adversely impact the database architect and future normalization. For a Candidate Key to qualify as a Primary Key, it should be Non-NULL and unique in any domain. I have observed quite often that Primary Keys are seldom changed. I would like to have your feedback on not changing a Primary Key.

主键 - 主键是唯一标识记录的列或列组合。只有一个候选键可以是主键。在选择主键时需要非常小心,因为不正确的选择会对数据库架构师和将来的规范化产生负面影响。要使Candidate Key成为主键,它应该是非NULL并且在任何域中都是唯一的。我经常观察到主键很少被改变。我想就不更改主键提供反馈。

For more articles

更多文章

#6


2  

A composite key is a primary key which has more than 1 column. For example consider the many to many relation between student and courses. Here we need another table , lets say studentcourses.

复合键是具有多于1列的主键。例如,考虑学生和课程之间的多对多关系。在这里,我们需要另一张桌子,让我们说学生课程。

This studentcourses table will have student_id and course_id as its columns. This will form your composite key.

该学生课程表将以student_id和course_id为列。这将形成您的复合键。

Candidate key is a set of columns which can uniquely identify the values in a table and can act as a unique key. One of these candidate keys will become the primary key and the rest will become alternate keys.

候选键是一组列,可以唯一地标识表中的值,并可以充当唯一键。其中一个候选键将成为主键,其余键将成为备用键。

Unique key as the name suggests , is used to uniquely identify a value in a table. For example Emp_id etc. Every candidate key will act as a unique key. Unique key can never be a NULL value.

顾名思义,唯一键用于唯一标识表中的值。例如,Emp_id等。每个候选键都将作为唯一键。唯一键永远不能是NULL值。

#7


0  

Since all the answers are missing physical representation and some of them are incomplete. So here is the difference by graphical representation

由于所有答案都缺少物理表示,其中一些是不完整的。所以这是图形表示的差异

主键,唯一键和候选键之间的区别


Explanation

Super Key

超级钥匙

Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.

超级密钥是一组一个或多个密钥,可用于在表中唯一地标识记录。

Example : Primary key, Unique key, Alternate key are subset of Super Keys.

示例:主键,唯一键,备用键是超级键的子集。

Candidate Key

候选钥匙

A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.

候选键是一组一个或多个字段/列,可以在表中唯一地标识记录。一个表中可以有多个候选键。每个候选键都可以作为主键。

Example: In above diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.

示例:在上图ID中,RollNo和EnrollNo是候选键,因为所有这三个字段都可以用作主键。

Primary Key

首要的关键

Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.

主键是表的一个或多个字段/列的集合,用于唯一标识数据库表中的记录。它不能接受null,重复的值。只有一个候选键可以是主键。

Alternate key

替代密钥

A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.

备用键是可用作主键的键。基本上它是当前不是主键的候选键。

Example: In above diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.

示例:在上图中,当我们将ID定义为主键时,RollNo和EnrollNo变为备用键。

Composite/Compound Key

复合/复合键

Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.

Composite Key是表的多个字段/列的组合。它可以是候选键,主键。

Unique Key

独特的钥匙

Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.

Uniquekey是表的一个或多个字段/列的集合,用于唯一标识数据库表中的记录。它类似于主键,但它只能接受一个空值,并且不能具有重复值。有关更多帮助,请参阅主键和唯一键之间的区别。

Foreign Key

外键

Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.

Foreign Key是数据库表中的一个字段,它是另一个表中的主键。它可以接受多个null,重复的值。有关更多帮助,请参阅主键和外键之间的区别。

Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.

示例:我们可以在Employee表中有一个DeptID列,该列指向department表中的DeptID列,该列是主键。

source

资源

#1


9  

Candidate key is a minimal (i.e. irreducible) key, unique key is a pleonasm, and primary key is an obsoleted concept still surviving from the days when people thought it possible for one key to be "more unique" than any of the others.

候选密钥是最小的(即不可简化的)密钥,唯一密钥是一个多余的密钥,而主键是一种过时的概念,当人们认为一个密钥可能比其他任何密钥“更独特”时,它仍然存在。

#2


13  

Super Key is the set of one or more column (ie attributes) which uniquely identifies a record.

超级密钥是唯一标识记录的一个或多个列(即属性)的集合。

Candidate key is a minimal Super key.(it mean we cant remove any attributes from it otherwise it will not remain Superkey anymore).

候选键是一个最小的超级键。(这意味着我们无法从中删除任何属性,否则它将不再保留超级键)。

Primary Key is a arbitrary selected Candidate key. There must be only and only One primary key. We can choose any candidate key as a Primary key. Other candidate keys which are not chosen as Primary are called Alternate Keys.

主键是任意选择的候选键。必须只有一个主键。我们可以选择任何候选键作为主键。未被选为主要的其他候选键称为备用键。

If Primary Key have more then one column (or attributes) ,it is called Composite Key.

如果主键有多个列(或属性),则称为复合键。

#3


4  

Google does not work anymore?

谷歌不再工作了?

http://en.wikipedia.org/wiki/Candidate_key

http://en.wikipedia.org/wiki/Candidate_key

http://en.wikipedia.org/wiki/Unique_key

http://en.wikipedia.org/wiki/Unique_key

#4


4  

Candidate keys - It is a column that can uniquely identify all columns for a specific row or instance of your database table. Your passport ID is a good example of a Candidate key and when using this ID you can retrieve a persons name, surname and other details related to that specific person.

候选键 - 它是一个列,可以唯一标识数据库表的特定行或实例的所有列。您的护照ID是候选密钥的一个很好的示例,使用此ID时,您可以检索与该特定人员相关的人员姓名和其他详细信息。

Primary key - There may be a few Candidate keys on a specific database table which is unique and can be used to identify a specific instance in a table e.g. Vehicle registration number, Chassis number, engine serial number etc... but remember there can only be one candidate key that will be used as a primary key. Difference between Candidate Key vs Primary Key:- ) Both Primary and Candidate keys can uniquely identify records in a table on database.

主键 - 特定数据库表上可能有一些候选键是唯一的,可用于标识表中的特定实例,例如车辆登记号,底盘号,发动机序列号等......但请记住,只能有一个候选钥匙用作主钥匙。候选密钥与主密钥之间的区别: - )主密钥和候选密钥都可以唯一地标识数据库中表中的记录。

2) Both Primary and Candidate keys are has constraints UNIQUE and NOT NULL.

2)主键和候选键都具有UNIQUE和NOT NULL约束。

3) Primary key or Candidate keys can be either single column or combination of multiple columns in a table.

3)主键或候选键可以是表中的单列或多列的组合。

#5


3  

Candidate Key – A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.

候选键 - 候选键可以是任何列或列的组合,可以作为数据库中的唯一键。一个表中可以有多个候选键。每个候选人密钥都可以作为主要密钥。

Primary Key – A Primary Key is a column or a combination of columns that uniquely identify a record. Only one Candidate Key can be Primary Key. One needs to be very careful in selecting the Primary Key as an incorrect selection can adversely impact the database architect and future normalization. For a Candidate Key to qualify as a Primary Key, it should be Non-NULL and unique in any domain. I have observed quite often that Primary Keys are seldom changed. I would like to have your feedback on not changing a Primary Key.

主键 - 主键是唯一标识记录的列或列组合。只有一个候选键可以是主键。在选择主键时需要非常小心,因为不正确的选择会对数据库架构师和将来的规范化产生负面影响。要使Candidate Key成为主键,它应该是非NULL并且在任何域中都是唯一的。我经常观察到主键很少被改变。我想就不更改主键提供反馈。

For more articles

更多文章

#6


2  

A composite key is a primary key which has more than 1 column. For example consider the many to many relation between student and courses. Here we need another table , lets say studentcourses.

复合键是具有多于1列的主键。例如,考虑学生和课程之间的多对多关系。在这里,我们需要另一张桌子,让我们说学生课程。

This studentcourses table will have student_id and course_id as its columns. This will form your composite key.

该学生课程表将以student_id和course_id为列。这将形成您的复合键。

Candidate key is a set of columns which can uniquely identify the values in a table and can act as a unique key. One of these candidate keys will become the primary key and the rest will become alternate keys.

候选键是一组列,可以唯一地标识表中的值,并可以充当唯一键。其中一个候选键将成为主键,其余键将成为备用键。

Unique key as the name suggests , is used to uniquely identify a value in a table. For example Emp_id etc. Every candidate key will act as a unique key. Unique key can never be a NULL value.

顾名思义,唯一键用于唯一标识表中的值。例如,Emp_id等。每个候选键都将作为唯一键。唯一键永远不能是NULL值。

#7


0  

Since all the answers are missing physical representation and some of them are incomplete. So here is the difference by graphical representation

由于所有答案都缺少物理表示,其中一些是不完整的。所以这是图形表示的差异

主键,唯一键和候选键之间的区别


Explanation

Super Key

超级钥匙

Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.

超级密钥是一组一个或多个密钥,可用于在表中唯一地标识记录。

Example : Primary key, Unique key, Alternate key are subset of Super Keys.

示例:主键,唯一键,备用键是超级键的子集。

Candidate Key

候选钥匙

A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.

候选键是一组一个或多个字段/列,可以在表中唯一地标识记录。一个表中可以有多个候选键。每个候选键都可以作为主键。

Example: In above diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.

示例:在上图ID中,RollNo和EnrollNo是候选键,因为所有这三个字段都可以用作主键。

Primary Key

首要的关键

Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.

主键是表的一个或多个字段/列的集合,用于唯一标识数据库表中的记录。它不能接受null,重复的值。只有一个候选键可以是主键。

Alternate key

替代密钥

A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.

备用键是可用作主键的键。基本上它是当前不是主键的候选键。

Example: In above diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.

示例:在上图中,当我们将ID定义为主键时,RollNo和EnrollNo变为备用键。

Composite/Compound Key

复合/复合键

Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.

Composite Key是表的多个字段/列的组合。它可以是候选键,主键。

Unique Key

独特的钥匙

Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.

Uniquekey是表的一个或多个字段/列的集合,用于唯一标识数据库表中的记录。它类似于主键,但它只能接受一个空值,并且不能具有重复值。有关更多帮助,请参阅主键和唯一键之间的区别。

Foreign Key

外键

Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.

Foreign Key是数据库表中的一个字段,它是另一个表中的主键。它可以接受多个null,重复的值。有关更多帮助,请参阅主键和外键之间的区别。

Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.

示例:我们可以在Employee表中有一个DeptID列,该列指向department表中的DeptID列,该列是主键。

source

资源