【问题标题】:sql DROP CONSTRAINT UNIQUE not workingsql DROP CONSTRAINT UNIQUE 不起作用
【发布时间】:2012-12-01 11:45:00
【问题描述】:

我得到了下表:

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_date 列是unique。现在我想放弃这种唯一性,因为我需要在 unsub_date + store_id 上有一个唯一索引。

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

ALTER TABLE `unsub_counts` DROP CONSTRAINT `unsub_date`

给我:你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“CONSTRAINT unsub_date”附近使用正确的语法

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

【问题讨论】:

  • 我不使用 MySQL,但看起来你没有为一个约束名传递一个约束名,而是一个列名。
  • FWIW 我在 Google 上搜索并发现 codeghar.wordpress.com/2008/03/28/… 建议删除伴随索引

标签: mysql unique-constraint sql-drop


【解决方案1】:

drop index 与约束名称一起使用:

ALTER TABLE unsub_counts DROP INDEX uc_unsub_date;

或者只是:

drop index uc_unsub_date on unsub_counts;

【讨论】:

  • 我错过了以uc_开头的索引名称。谢谢,它成功了
猜你喜欢
  • 2020-08-06
  • 2012-01-16
  • 2012-03-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-06
  • 2019-07-12
  • 2019-02-11
  • 2018-10-29
相关资源
最近更新 更多