The title: Primary key superkey candidate key What are foreign keys

define

Super key: The set of attributes that uniquely identify a tuple in a relationship is called a relational superkey

Candidate keys: Superkeys that do not have redundant attributes are called candidate keys. If you delete an attribute from a candidate key, it’s no longer a key!

Primary key: A program primary key selected by the user as a candidate key for tuple identification

Foreign key: if the attribute K in relational schema R is the primary key of another schema, then K is called a foreign key in schema R.

For example,

For example, there are the following data:

Student id The name gender age Is don’t professional
20020612 Li hui male 20 The computer Software development
20060613 Zhang Ming male 18 The computer Software development
20060614 Xiao-yu wang female 19 physical mechanics
20060615 Shu-hua lee female 17 biological zoology
20060616 jing male 21 chemical Food chemistry
20060617 jing female 20 biological botany
  1. Super key

    The set of attributes that uniquely identify a tuple in a relationship is called the superkey of the relational schema.

    Therefore, we can see from the example that the student number is the unique identification of the student entity. The superkey of that tuple is the student number.

    We can also combine it with other attributes, such as:

    (Student ID, Gender)

    (Student ID, Age)

    That’s also a superbond.

  2. Candidate key

    A superkey with no redundant attributes is a candidate key.

    Student number is a unique identifier that uniquely identifies a tuple, so student number is a candidate key. In fact, a candidate key is a subset of the superkey. For example, (student number, age) is a superkey, but it is not a candidate key. Because it has additional properties.

  3. A primary key

    The candidate key selected by the user as the unique identity of the tuple is the primary key.

    To put it simply, the candidate key for the tuple in this example is the student number, but if we select it as the unique identifier for the tuple, the student number is the primary key.

  4. A foreign key

    The foreign key is relative to the primary key, for example, in the student record, the primary key is the student number, in the transcript table also has the student number field, so the student number is the foreign key of the transcript table, is the primary key of the student table.

conclusion

Primary keys are a subset of candidate keys, candidate keys are a subset of superkeys, and foreign keys are determined relative to primary keys.