如何确保表实体中的值不会在mysql中重复?
在下表中,我希望属性_id是唯一的,这样它就不会有重复的值。这个的语法是什么如何确保表实体中的值不会在mysql中重复?,mysql,Mysql,在下表中,我希望属性_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, `propert
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;
您可以将
UNIQUE
约束添加到property\u id
列中,以便在需要时不允许重复
要检查重复项,可以运行以下查询:
select property_id, count(property_id) as total from propFeatures
group by property_id having count(property_id) > 1
如果要删除重复项,请查看此帖子以了解更多信息:
您可以在
属性id
列中添加唯一的
约束,以便在需要时不允许重复
要检查重复项,可以运行以下查询:
select property_id, count(property_id) as total from propFeatures
group by property_id having count(property_id) > 1
如果要删除重复项,请查看此帖子以了解更多信息: