在下表中我希望property_id是唯一的,以便它没有重复的值。这是什么语法?
CREATE TABLE IF NOT EXISTS `propFeatures` (
`id` bigint(20) NOT NULL auto_increment,
`bedroom` int(10) NOT NULL,
`bathroom` int(10) NOT NULL,
`balcony` int(10) NOT NULL,
`furnished` tinyint(1) NOT NULL,
`property_id` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
答案 0 :(得分:1)
您可以将UNIQUE
约束添加到property_id
列,以便在需要时不允许重复。
要检查重复项,您可以运行此查询:
select property_id, count(property_id) as total from propFeatures
group by property_id having count(property_id) > 1
如果您想删除重复项,请查看此帖子以获取更多信息: