First example
WHOSE
- WH -> S
- HOS -> E
Steps:
- Find the attributes that are neither on the left and right side(找到依赖两侧都没有的属性)
(none)
- Find attributes that are only on the right side
(找到只在依赖右侧出现的属性)
E
- Find attributes that are only on the left side
(找到只在依赖左侧出现的属性)
WHO
- Combine the attributes on step 1 and 3
(把第一步和第三步中找到的属性合并)
since step 1 has no attributes, it’s just WHO
- Test if the closures of attributes on step 4 are all the attributes
(测试第四步中的属性 所形成的回路 是否就是所有属性)
in our case, yes it is. Because with WH we can get S, and by HOS, we can get E.
So we have only one candidate key, that is WHO.
Third example
ABCD
- ABC -> D
- D -> A
Steps:
- –
- –
- BC
- BC
- The closure of BC is only BC, we should find the relation exterior.
- Find the relation exteriors, that is the attributes not included in step 4 and step 2.
in this example it is AD
- Now test the closures of attributes on step 4 + one attribute in step 6 one at a time.
ABC closures are ABCD, so it is a candidate key
BCD closures are ABCD, so it is also a candidate key
so in this case we have two candidate keys, they are ABC and BCD.