更改整个表中 MySQL ENUM 值的值

发布于 2024-12-05 14:49:27 字数 81 浏览 1 评论 0原文

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

I'm wondering if it is possible to change an ENUM value throughout a table, so that in all the rows where said ENUM value is represented, the change is made as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-12-12 14:49:27

如果你想改变枚举的值:

假设你的旧枚举是:

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可能会遍历表中的所有行来尝试更新内容,我听说过围绕它进行计划优化的故事,但我不确定这是否真的发生了。

If you want to change the value of an enum:

Suppose your old enum was:

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

To change that use:

--  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 will probably go through all the rows in your table trying to update stuff, I've heard stories of a planned optimization around that, but I'm not sure if that actually happened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文