我有下表,我想知道如何知道获取主键,超级键和候选键。
我知道候选键是超级键的最小值。
这是正确的主键PlaceId CountyId
,候选键PlaceId, CountyId, Date
和超级键PlaceId, CountyId, Date, Attendees
吗?
CREATE TABLE IF NOT EXISTS `visits` (
`PlaceId` varchar(45) DEFAULT NULL,
`CountyId` varchar(45) DEFAULT NULL,
`Date` date NOT NULL,
`Attendees` varchar(45) DEFAULT NULL,
INSERT INTO `visits` (`PlaceId`, `CountyId`, `Date`, `Attendees`) VALUES
('Bangor', 'Gwynedd', '2012-05-03', '34'),
('Bangor', 'Gwynedd', '2012-05-04', '24'),
('Rhyl', 'Denbighshire', '2012-05-06', '14');
答案 0 :(得分:1)
根据您提供的示例数据以及我对地点,县,日期和与会者<的理解/ em> mean,唯一的候选键是{PlaceId,CountyId,Date}。
由于只有一个候选键,该候选键也必须是主键。
所有属性的集合都是一个简单的超级键。所以一个超级钥匙是{PlaceId,CountyId,Date,Attendees}。另一个是{PlaceId,CountyId,Date}。