Identification of key, main key and candidate key in database

Primary key, Candidate key, Key

ps: A tuple is understood as a row of a table, an attribute is understood as a column of a table, and the attribute name is the name of the column (field).

1 (code): A code is an attribute name or attribute name group that can determine all information of a tuple .

For example in { a, b, c, d },

Suppose knowing the value of a can determine the values ​​of a, b, c, d,

Assuming that the values ​​of c and d are known, the values ​​of a, b, c, and d can be determined.

Then { a } is the code, and { c, d } is the code.

And { a, b }, { a, c }, { a, b, c }, { a, b, c, d } etc. are also codes, because they can also determine all values ​​of a tuple, even if many Remain.

2 (candidate code): There is no code in the proper subset of the candidate code, and there can be multiple candidate codes.

As far as the above example is concerned, { a } is a candidate key, and { c, d } are candidate keys because there are no keys in their proper subsets.

And such as { a, b } is not a candidate key, because its proper subset contains { a }, and { a } is a key.

3 (Primary key): The primary key means the primary key, and the primary key is any candidate key.

Still in the above example, the primary key is one of the candidate keys { a }, { c, d }.

It can be either { a } or { c, d }.

Guess you like

Origin blog.csdn.net/weixin_41866717/article/details/115438726