1. Definition
- Super key: The set of attributes that can uniquely identify a tuple in a relationship is called the super key of the relationship schema
- Candidate key (candidate key): a super key that does not contain redundant attributes is called a candidate key
- primary key: a candidate key selected by the user as a tuple identification program primary key
2. Relationship diagram
3. Examples
Person (ID name, gender, age)
Assuming no duplication
Parse:
- The ID is unique, so it is a super key
- The name is unique, so it is a superkey
- (name, gender) is unique, so is a superkey
- (name, age) is unique, so is a superkey
- (name, gender, age) is unique, so is a superkey
--It can be seen here that the combination of super keys is unique, but may not be the smallest unique
- The ID card is unique and has no redundant attributes, so it is a candidate key
- The name is unique and there are no redundant attributes, so it is a candidate key
- Although (name, gender) is unique, a single attribute of name can determine who this person is, so the attribute of gender is a redundant attribute, so (name, gender) is not a candidate key
- name, age), (name, gender, age) as above, also not candidate keys
--It can be seen here that the candidate key is a super key with no redundant attributes
- Considering the convenience of input and query, you can choose the ID card as the primary key
- You can also consider the custom to choose the name as the primary key
--Primary key is a selected candidate key
Reprinted from: http://blog.csdn.net/cjr15233661143/article/details/12970323