Alter a live table to make a key non-unique

后端 未结 3 1963
故里飘歌
故里飘歌 2020-12-20 12:13

I saw some other questions related to this, but they were not MySQL.

The database is a live database, so I don\'t want to delete and recreate the table. I simply wan

3条回答
  •  自闭症患者
    2020-12-20 12:28

    If your column was defined unique using UNIQUE clause, then use:

    ALTER TABLE mytable DROP INDEX constraint_name
    

    , or, if your constraint was implicitly named,

    ALTER TABLE mytable DROP INDEX column_name
    

    If it was defined unique using PRIMARY KEY clause, use:

    ALTER TABLE mytable DROP PRIMARY KEY
    

    Note, however, that if your table is InnoDB, dropping PRIMARY KEY will result in implicit recreation of your table and rebuilding all indexes, which will lock the table and may make it inaccessible for quite a long time.

提交回复
热议问题