Search code examples
database-designfunctional-dependenciescandidate-key

Find all candidate keys that consist of 3 attributes if any? Sample Midterm


This is a question from a sample midterm from my database course. The solution is not given to us for the midterm and i just wanted to ask if my solution is correct in any sense

Consider the following relation T=(N,A,I,V,L,P,C,D)

with the FD={N->AI , AV->LP, VC->PD, VL->P, LA->D, NP->IVL, CID-> LVP, AD->IP}
Find all candidate keys that consist of 3 attributes if any? 

I attempted to solve the question and this is what i got:

Left Attributes = N,C
Middle Attributes = A,I,V,L,P,D
Right Attributes = None

I then made 3 attribute pairs with NC and found their closures:

NC+ = {NCAI} NO
NCA+ = {NCA} NO
NCI+ = {NCI} NO
NCV+ = {NCVPDAIL} = Get PD from VC->PD AND AI from N->AI and L from NP->IVL? Is this correct? If IV is already in there can I use this dependency to get L?
NCL+ ={NCLAIDVP} = Get AI from N->AI & D from LA->A and VP from CID->LVP using same logic from above?
NCP+ = {NCPAIVLD} straight forward using same logic from above
NCD+ = {NCDAILVD} YES

So i got 4 candidate keys that have 3 attributes in them. which are NCV, NCL, NCP, NCD.

So did i nail it or there should only be one candidate key which should be NCD?

Thank you!


Solution

  • You have given the correct answer. The relation has only four candidate keys, NCV, NCL, NCP, NCD, all with three attributes.

    N and C must be always be present in every key, since they appear only in the left part. Trying to add to them the other attributes and computing the closure is what is needed to check which are the keys. Note that NCA+ and NCI+ are equal to NC+ and produces NCAI. You should try also the combination NCAI+, but the result is the same. So, at the end, each of the four attributes V L P and D added to NC generates a key, and your answer is correct.