Alter a live table to make a key non-unique

若如初见. 提交于 2019-12-18 07:33:36

问题


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 want to make a column no longer unique, which is less permissive in nature so it shouldn't cause any problems.


回答1:


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.




回答2:


These are instructions for phpmyadmin app (if you are using phpMyAdmin) ::

In a some cases, the developer (you) may not want to drop it but rather just modify the "uniqueness" to "not-unique".

Steps :

  1. Go to the table in context, where you want to make the modification

  2. Click on the "Structure" tab (mostly next to Browse)

  3. Look for the "+Indexes" link, just under the columns. Yeah... now click it
  4. Now you can see all the "Indexes" and you can now click on the "DROP" button or link to modify.

Answer was found here : Source : https://forums.phpfreaks.com/topic/164827-phpmyadmin-how-to-make-not-unique/




回答3:


Just DROP the unique index. There shouldn't be a problem with the fact that it is a live DB. If it is a really large table, you may block some queries temporarily while the index is removed. But that should only happen if you were adding an index.

ALTER TABLE table_name DROP INDEX index_name;


来源:https://stackoverflow.com/questions/4140402/alter-a-live-table-to-make-a-key-non-unique

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