sql DROP CONSTRAINT UNIQUE not working

為{幸葍}努か 提交于 2019-12-11 23:59:38

问题


I got the following table:

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;

where column unsub_date is unique. Now I want to drop that uniqueness, because I need to have a unique index on unsub_date + store_id.

I found suggestions on the net, but is failing:

ALTER TABLE `unsub_counts` DROP CONSTRAINT `unsub_date`

gives me: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT unsub_date' at line 1

Is this related to MyISAM? Any other suggestions?


回答1:


Use drop index with constraint name:

ALTER TABLE unsub_counts DROP INDEX uc_unsub_date;

or just:

drop index uc_unsub_date on unsub_counts;


来源:https://stackoverflow.com/questions/13659114/sql-drop-constraint-unique-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!