日期:2014-05-16  浏览次数:21032 次

mysql 创建唯一索引 出错
mysql 数据库创建唯一索引提示如下错误:

ERROR 1831 (HY000): Duplicate index 'index2_id' defined on the table 'example.index2'. This is deprecated and will be disallowed in a future release.

sql语句如下:
create table index2(
id int unique,
name varchar(20),
unique index index2_id(id ASC)
);

不知道哪里出了错误,请各位大神帮忙
------解决方案--------------------
你要检查一下里面的id,是否有重复值:
select id,count(id)
from index2
group by id
having count(id)>1
这是sqlserver的写法,mysql不保证能用
------解决方案--------------------
mysql语法不熟,不知道能不能执行,你要多看文档啊,另外下次可以发到【其他数据库开发】→【mysql】专区
create table index2(
id int ,
name varchar(20)
);

create unique index index2_id(id ASC)