Super key, candidate key, primary key

Super key (super key): in the relationship attribute set can uniquely identify a tuple of the relational schema called a super key
candidate key (candidate key): Super key does not contain unnecessary candidate key attribute called
the primary key (primary key): user Program primary key selected as a candidate key for tuple identification

For example, for a small group of people who have no duplicate names, consider the following attributes

ID card name gender age

The only ID cards, so there is a super key
name unique, so there is a super key
(name, gender) unique, so there is a super key
(name, sex, age) unique, it is a super key
- here we can see, super The key combination is unique, but may not be the smallest unique

The only ID cards, and no excess property, it is a candidate key
name unique, and no excess property, it is a candidate key
- here we can see, there is no candidate key attribute of super-extra key

Consider entering a query convenience, you can select ID as the primary key
can also be used to select a name to consider the primary key
- primary key is a candidate key selected

What is the one question they get to know a candidate key
look first topic
in the SQL Server database, there is a student information shown in the following table, the table can not be a candidate key is a set of attributes () (choose one)
Student ID Name Sex Age Department Major
20020612 Li Huinan 20 Computer Software Development
20060613 Zhang Mingnan 18 Computer Software Development
20060614 Wang Xiaoyu Girl 19 Physical Mechanics 20060615
Li Shuhua Girl 17 Biological Zoology
20060616 Zhao Jingnan 21 Chemistry Food Chemistry
20060617 Zhao Jing Girl 20 Biological Botany
a) {Science Number}
b) {student number, name}
c) {age, department}
d) {name, gender}
e) {name, major}
Maybe you don’t know how to choose. If we can answer this question correctly, then we have a deep understanding of the concepts of super keys and candidate keys and primary keys.
Look at the concept:
Super key: The set of attributes that can uniquely identify tuples in the relationship is called the super key of the relationship mode.
Candidate keys: Super keys that do not contain redundant attributes are called candidate keys. That is, in the candidate key, if you want to delete the attribute, it is not a key.
Primary key: A candidate key selected by the user as a tuple identifier is called the 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 grandpa super key is the only one.
Let's analyze the above questions, abcde5 answers can all be used as super keys, and their combined set can be used to uniquely identify a data record (entity).
Please pay attention to our requirements: candidate keys. The candidate key requirement is a super key that cannot contain redundant attributes. Let's look at answer b. In answer to (b), if we do not use names can only
identify a data entity, the name field can be said here is redundant. So obviously, the b option contains redundant field attributes. Then the answer to this question should be b

Then the other four options can be used as candidate keys, assuming lucky, a) student number is selected as a candidate key user is using to uniquely identify a tuple, then he was lucky enough to
get the title of master keys "

Fully functional dependency

If the non-primary attribute B function depends on a set of principal attributes A that constitute a certain candidate key, and any proper subset of A cannot be dependent on the B function, then B is fully functionally dependent on A; on the contrary, if the B function can depend on For the proper subset of A, it is said that part of the function of B depends on A.

Recorded as: as shown in the figure

And give an example:

Example: In the relationship of the transcript (student number, course number, grade),

Complete functional dependence: (student number, course number) → grade, student number -\→ grade, course number -\→ grade, so (student number, course number) → grade is completely functional dependent

Guess you like

Origin blog.csdn.net/ke_weiquan/article/details/53025377