sql DROP CONSTRAINT UNIQUE无法正常工作

时间:2012-12-01 11:45:00

标签: mysql unique-constraint sql-drop

我得到了下表:

CREATE TABLE `unsub_counts` (
 `count_id` int(11) NOT NULL AUTO_INCREMENT,
 `unsub_date` date DEFAULT NULL,
 `unsub_count` int(11) DEFAULT NULL,
 `store_id` smallint(5) DEFAULT NULL,
 PRIMARY KEY (`count_id`),
 UNIQUE KEY `uc_unsub_date` (`unsub_date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

unsub_dateunique。现在我想放弃这种唯一性,因为我需要在unsub_date + store_id上有一个唯一索引。

我在网上找到了建议,但失败了:

ALTER TABLE `unsub_counts` DROP CONSTRAINT `unsub_date`

给了我:你的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#CONS;约束unsub_date'附近使用正确的语法。在第1行

这与MyISAM有关吗?还有其他建议吗?

1 个答案:

答案 0 :(得分:1)

使用约束名称为drop index

ALTER TABLE unsub_counts DROP INDEX uc_unsub_date;

或只是:

drop index uc_unsub_date on unsub_counts;