The distinction between a super-key, a candidate key, and a primary key in a database

Source: Internet
Author: User

Super key: An attribute set that uniquely identifies a tuple in a relationship is called a hyper-key of a relational pattern
Candidate key (candidate Key): A super-key that does not contain extra attributes is called a candidate key
Primary key (primary key): A candidate key program primary key that the user selected as a tuple identity

For example, a small range of people, without the same name, consider the following attributes:
ID, name, gender, age.

ID card The only so is a super key
Name unique so it's a super key
(name, gender) the only so is a super key
(name, gender, age) the only so is a super key
--as can be seen here, the combination of the super-key is unique, but may not be the smallest unique

ID card is unique and has no extra attributes so it's a candidate key.
The name is unique and has no extra attributes so it's a candidate key.
--Here you can see that the candidate key is a super-key with no extra attributes

Consider the convenience of input query, choose Identity Card as the primary key
You can also consider the habit, select the name as the primary key
--The primary key is a selected candidate key

A question that understands what a candidate key is:

In the SQL Server database, there is a student information table as shown below, in which a collection of attributes that cannot be a candidate key is () (select an item)
School Number name Gender Age Department major
20020612 Li Hui male 20 computer software development
20060613 Zhang Ming man 18 computer software development
20060614 Wang Xiao herself 19 physical mechanics
20060615 Li Shuhua Female 17 biological zoology
20060616 Zhao Jing Men 21 Chemical food Chemistry
20060617 Zhao Static female 20 biological botany
A) {study number}
b) {School number, name}
c) {age, Department}
d) {name, gender}
e) {name, professional}

Maybe people don't know how to choose. If we can solve the problem correctly, we have a deep understanding of the concept of the super-key and the candidate key and the primary key.
Through the concept, we can see that the super-key contains the candidate key, and the candidate key contains the primary key. The primary key must be unique. Why is it? Because his grandfather's super-key is the only one.
We analyze the above topic, ABCDE5 the answer can be as a super-key, the combination of their collection can be used to uniquely identify an entity.
Please note our requirements: Candidate keys. The candidate key requirement is a super-key that cannot contain extra attributes, so let's take a look at answer B. In answer B, if we do not use the name can also uniquely identify a data entity, you can say that the name field is superfluous here. Then obviously, the B option contains the extra field properties. So the answer to this question should be B.
Then the other 4 options can be used as a candidate key, assuming that fortunately, a) is selected as the user is using a candidate key to uniquely identify the tuple, then he was lucky to get the title of the primary key (key-and candidate key).

Transferred from: http://blog.sina.com.cn/s/blog_6d677b680100sveh.html

The distinction between a super-key, a candidate key, and a primary key in a database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.