How to drop unique in MySQL?

前端 未结 10 754
[愿得一人]
[愿得一人] 2020-12-07 11:20
Create Table: CREATE TABLE `fuinfo` (
  `fid` int(10) unsigned NOT NULL,
  `name` varchar(40) NOT NULL,
  `email` varchar(128) NOT NULL,
  UNIQUE KEY `email` (`email         


        
10条回答
  •  伪装坚强ぢ
    2020-12-07 11:50

    There is a better way which don't need you to alter the table:

    mysql> DROP INDEX email ON fuinfo;
    

    where email is the name of unique key (index).

    You can also bring it back like that:

    mysql> CREATE UNIQUE INDEX email ON fuinfo(email);
    

    where email after IDEX is the name of the index and it's not optional. You can use KEY instead of INDEX.

    Also it's possible to create (remove) multicolumn unique indecies like that:

    mysql> CREATE UNIQUE INDEX email_fid ON fuinfo(email, fid);
    mysql> DROP INDEX email_fid ON fuinfo;
    

    If you didn't specify the name of multicolumn index you can remove it like that:

    mysql> DROP INDEX email ON fuinfo;
    

    where email is the column name.

提交回复
热议问题