Think before you speak, read before you think.

mysql添加联合唯一索引

by

in

为表 project_server 添加联合唯一索引

mysql> alter table project_server add unique index(project_id,object_id);
ERROR 1062 (23000): Duplicate entry '11-1177' for key 'project_id'

如果提示说记录已经存在,那么加上 ignore,会自动将重复的去掉,很有效

mysql> alter ignore table project_server add unique index(project_id,object_id);
Query OK, 166 rows affected (0.06 sec)
Records: 166  Duplicates: 1  Warnings: 0

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *