MySQL 更改活动表以使键不唯一

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4140402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:41:16  来源:igfitidea点击:

Alter a live table to make a key non-unique

mysqluniquealter-table

提问by Alexander Bird

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

我看到了一些与此相关的其他问题,但它们不是 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.

该数据库是一个实时数据库,所以我不想删除和重新创建表。我只是想让一个列不再是唯一的,这在本质上是不那么宽松的,所以它不应该引起任何问题。

回答by Quassnoi

If your column was defined unique using UNIQUEclause, then use:

如果您的列被定义为唯一 usingUNIQUE子句,则使用:

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 KEYclause, use:

如果它被定义为唯一的 usingPRIMARY KEY子句,请使用:

ALTER TABLE mytable DROP PRIMARY KEY

Note, however, that if your table is InnoDB, dropping PRIMARY KEYwill 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.

但是请注意,如果您的表是InnoDB,删除PRIMARY KEY将导致隐式重新创建您的表并重建所有索引,这将锁定表并可能使其在很长一段时间内无法访问。

回答by AppEmmanuel

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

这些是 phpmyadmin 应用程序的说明(如果您使用的是 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.
  1. 转到上下文中的表,您要在其中进行修改

  2. 单击“结构”选项卡(主要在浏览旁边)

  3. 查找列下方的“+索引”链接。是的...现在点击它
  4. 现在您可以看到所有“索引”,您现在可以单击“删除”按钮或链接进行修改。

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

在这里找到答案:来源:https: //forums.phpfreaks.com/topic/164827-phpmyadmin-how-to-make-not-unique/

回答by Jason McCreary

Just DROPthe unique index. There shouldn'tbe 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 shouldonly happen if you were adding an index.

只是DROP唯一索引。这里不应该是一个事实,即它是一个活的DB的问题。如果它是一个非常大的表,您可能会在删除索引的同时暂时阻塞一些查询。但是,这应该如果你添加索引才会发生。

ALTER TABLE table_name DROP INDEX index_name;