Super key
Definition: In relational mode, the set of attributes that uniquely identify a tuple is called a Super Key.
T_student (id, name, age, sex)
The core of a superkey definition is that it uniquely identifies a meta-ancestor and is also a set of attributes. In general, we need to find a student, no matter the name or gender can not be accurately found, there can also be students with the same name and age in the data, so in the above relationship model, only through the student number can find a specific student.
Therefore, only the set of attributes containing student numbers in the above relational schema can be called a superkey:
Examples :(id), (id, name), (id, name, age), etc
Candidate key
Definition: In relational mode, a set of attributes that uniquely identifies a tuple and does not contain redundant attributes is called a Candidate Key.
T_student (id, name, age, sex)
Unlike the superkey definition, it can contain no redundant attributes; Data without any hypothesis of the above example, a student’s name is repetitive, so we can through the student id, students can also be determined by a particular name only, then all contain student number, name of the property set we can all be called the key, but not include redundant attribute set of attributes, said if we delete properties can no longer be called a key, A candidate key is a special superkey.
Therefore, only individual student numbers and name attribute sets in the above relational schema can be called candidate keys:
Example: (id), (name)
A primary key
Definition: Specify a Key randomly among several candidate keys in a relational schema. This Key is the Primary Key.
T_student (id, name, age, sex)
Primary key is easy to understand, in the basis of the candidate key arbitrarily choose one as the primary key, at the same time derived from the compound primary key and the joint primary key, assuming that we do not have the student number field, if we can find a specific student through the name, age, gender, then we call (name, age, sex) as the compound primary key, Those consisting entirely of primary keys are called joint primary keys.
Therefore, in the above relational mode, the name can also uniquely identify the student, then the primary key is:
Example: (id), (name)
A foreign key
Definition: if an attribute in R1 is not a candidate Key of R1, but a candidate Key in R2, the attribute set is a Foreign Key for R1.
T_student (id, name, age, sex, class_id), t_classroom(id, class_name)
Foreign key in the relationship between two model is established, can know from the above definition, the primary key in a relational schema of a must be the candidate key, for another relationship, as long as the original relationship between the primary key of the said only common attributes, it is another foreign key attribute, the table in the classroom, students is the foreign key in the table, its main function is to keep data consistency and integrity.
The diagram