查找给定关系和功能依赖关系的主键

时间:2015-06-15 11:24:38

标签: sql database primary-key

考虑到这种关系:

竞争对手(PID,EventName,Pname,TeamName,TeamCoach, EventDate,TeamRating)

功能依赖:

PID -> Pname, TeamName, TeamCoach 
TeamName -> TeamCoach 
EventName -> EventDate 
TeamName, EventName -> TeamRating 

根据我的知识,我认为主键是{PID,EventName,TeamName}

提供的答案说主键是{PID,EventName}

我错了(很可能)或提供的答案是错误的。

如果你能告诉我哪个是对的以及你如何找到它的方法,那就太好了。

1 个答案:

答案 0 :(得分:0)

你的答案是超级密钥,它可以被认定为主键。但是,这不是最好的答案。最好的答案是{PID,EventName}。你的答案不是cadiate key。

您可以通过查找候选键来找到候选键。如果它等于{PID,EventName,Pname,TeamName,TeamCoach,EventDate,TeamRating},则它是候选键。您可以在此站点中找到查找闭包算法:http://www.cs.sfu.ca/CourseCentral/354/jpei/slides/ClosureDecomposition.pdf

The closures of {PID, EventName} :

C={PID, EventName}

Function: PID -> Pname, TeamName, TeamCoach 
C= {PID, EventName, Pname, TeamName, TeamCoach }

Function: EventName -> EventDate
C={PID, EventName, Pname, TeamName, TeamCoach ,EventDate}

Function: TeamName, EventName -> TeamRating 
C={PID, EventName, Pname, TeamName, TeamCoach ,EventDate,TeamRating}