Database-Super Key, candidate key, primary key, foreign key

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 that the user selected as a tuple ID becomes the primary key
Foreign key (foreign key) if the set of properties in the relational schema R1 is not the primary key of the R1, but the primary key of the other relationship R2, the property set is the foreign key of the relational schema R1.

Specific explanations of the examples:

Suppose you have the following two tables:
Student (school number, name, gender, social Security number, teacher number)
Teacher (teacher number, name, salary)

Super key:
The definition of a super-key indicates that any combination of the student's number or a social Security number is a super-key for the table. such as: (School Number), (school number, name), (Social Security number, gender) and so on.

Candidate Key:
A candidate key is a super-key, which is the smallest super-key, meaning that if you remove any of the candidate keys, it is no longer a super-key. The candidate keys in the student table are: (Student number), (Social Security number).

Primary key:
The primary key is one of the candidate keys, is a man-made rule, for example, in the student table, we usually let the "learning number" key, teachers table let "teacher number" key.

Foreign keys are relatively simple, and the foreign keys in the student table are "teacher numbers". A foreign key is primarily used to describe the relationship of two tables.

Database-Super Key, candidate key, primary key, foreign key

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: 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.