修改活动表以使键不唯一 [英] Alter a live table to make a key non-unique
问题描述
我看到了与此有关的其他一些问题,但它们不是MySQL.
该数据库是一个实时数据库,因此我不想删除并重新创建该表.我只是想使一列不再唯一,它本质上不太宽松,因此不会引起任何问题.
如果使用UNIQUE
子句将您的列定义为唯一,则使用:
ALTER TABLE mytable DROP INDEX constraint_name
,或者,如果您的约束是隐式命名的,
ALTER TABLE mytable DROP INDEX column_name
如果使用PRIMARY KEY
子句将其定义为唯一,请使用:
ALTER TABLE mytable DROP PRIMARY KEY
但是,请注意,如果表为InnoDB
,则删除PRIMARY KEY
会导致表的隐式重新创建并重建所有索引,这将锁定该表并可能使它在相当长的时间内无法访问. /p>
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.
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.
这篇关于修改活动表以使键不唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!