簡體   English   中英

在整個表中更改MySQL ENUM值的值

[英]Changing the Value of a MySQL ENUM Value, Throughout a Table

我想知道是否可以在整個表中更改ENUM值,以便在表示所述ENUM值的所有行中也進行更改。

如果要更改枚舉的值:

假設您的舊枚舉是:

ENUM('English', 'Spanish', 'Frenchdghgshd', 'Chinese', 'German', 'Japanese') 

要改變這種用途:

--  Add a new enum value
ALTER TABLE `tablename` CHANGE `fieldname` `fieldname` ENUM   
('English', 'Spanish', 'Frenchdghgshd', 'Chinese', 'German', 'Japanese', 'French');
-- Update the table to change all the values around.
UPDATE tablename SET fieldname = 'French' WHERE fieldname = 'Frenchdghgshd';
-- Remove the wrong enum from the definition
ALTER TABLE `tablename` CHANGE `fieldname` `fieldname` ENUM   
('English', 'Spanish', 'Chinese', 'German', 'Japanese', 'French');

MySQL可能會通過你表中的所有行來嘗試更新內容,我聽說有關計划優化的故事,但我不確定這是否真的發生了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM