What are the differences between superkeys, candidate keys, and primary keys?

Source: Internet
Author: User

Super key: the attribute set that uniquely identifies a tuples in a link is called the super key of the link mode.
Candidate Key: A super key without redundant attributes is called a candidate key.
Primary Key (primary key): The primary key of a candidate key program selected as a tuples

For example, if there is no duplicate name for all people in a small range, consider the following attributes:

ID Card Name gender age

The ID card is unique, so it is a super key
The name is unique, so it is a super key
(Name, gender) is unique, so it is a super key
(Name, gender, age) is unique, so it is a superkey
-- It can be seen that the combination of superkeys is unique, but it may not be the smallest and unique

The ID card is unique and has no redundant attributes. Therefore, it is a candidate key.
The name is unique and has no redundant attributes. Therefore, it is a candidate key.
-- We can see that the candidate key is a super key without any redundant attributes.

To facilitate input query, you can select the ID card as the primary key.
You can also select the name as the primary key.
-- The primary key is a selected candidate key.

I understand what is a candidate key
Take a look at the question first
In the SQL Server database, there is a student information table as follows. In this table, the attribute set that cannot be used as the candidate key is () (select one)
Student ID name gender age Division Major
20020612 Li Hui male 20 Computer Software Development
20060613 Zhang mingnan 18 Computer Software Development
20060614 Wang Xiaoyu female 19 physical mechanics
20060615 Li Shuhua, female 17 biological Animal Science
20060616 Zhao jingnan 21 chemical food chemistry
20060617 Zhao jingfemale 20 Bioinformatics
A) {student ID}
B) {student ID, name}
C) {age, Department}
D) {name, gender}
E) {name, Major}
You may not know how to choose. If we can answer this question correctly, we have a deep understanding of the concepts of the superkeys and candidate keys and primary keys.
See the following concepts:
Superkey: the attribute set that uniquely identifies a tuples in a link is called the superkey of The Link mode.
Candidate Key: A super key without additional attributes is called a candidate key. That is, in the candidate key, if you want to delete the attribute again, it is not a key.
Primary Key: A candidate key selected as a tuples is called a primary key.
U <6 {mzh = | M
Through the concept, we can understand that the super key contains the candidate key, and the candidate key contains the primary key. The primary key must be unique. Why? Because his grandfather's key is unique.
Let's take a look at the above questions. abcde5 answers can all be used as superkeys, and a collection of them can be used to uniquely identify a data record (entity ).
Note our requirements: candidate keys. The candidate key must be a super key that does not contain redundant attributes. Let's take a look at Answer B. In answer B, if we do not use a name, it can be unique.
Identifies a data entity. It can be said that the name field is redundant here. Obviously, option B contains extra field attributes. Then the answer to this question should be B.

The other four options can be used as candidate keys. If you are lucky, A) The student ID is selected as the candidate key that the user is using to uniquely identify the tuples.
Won the title of primary key

Http://hi.baidu.com/fx0517/blog/item/fa72bade3cf00c53ccbf1a9d.html

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.