小学,考生和超级键

时间:2012-05-14 07:18:15

标签: sql database-design primary-key create-table

我有下表,我想知道如何知道获取主键,超级键和候选键。

我知道候选键是超级键的最小值。

这是正确的主键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');

1 个答案:

答案 0 :(得分:1)

根据您提供的示例数据以及我对地点日期与会者<的理解/ em> mean,唯一的候选键是{PlaceId,CountyId,Date}。

由于只有一个候选键,该候选键也必须是主键。

所有属性的集合都是一个简单的超级键。所以一个超级钥匙是{PlaceId,CountyId,Date,Attendees}。另一个是{PlaceId,CountyId,Date}。