mysql - 如何根据行名复制 MySQL 行(1),然后更改行名(2)
问题描述
我有一个包含很多子站点的 WP 多站点。
- 我想使用 option_name“theme_mods_my-theme”复制所有行。
- 并在复制后将其更改为“theme_mods_my-new-theme”。
- 不得删除或更改原始的“theme_mods_my-theme”。
行名称是唯一的,但有多个表显示此行。这些行的值是唯一的。行名称出现在这些表中,例如:
- mywpsite_18_options // 子站点 ID 18
- mywpsite_17_options // 子站点 ID 17
- mywpsite_16_options // 子站点 ID 16
- 等等
任何帮助深表感谢。
我想我需要这样的东西:
INSERT INTO `mywpsite_17_options` (`option_id`, `option_name`, `option_value`, `autoload`)
VALUES
(31940, 'theme_mods_my-theme', '[The values]', 'yes');
唯一的事情是:
- 它需要搜索名称为 mywpsite_XX_options 的所有表
- 在每个表的 option_name 列中找到 theme_mods_my-theme
- 像上面一样复制(插入)到每个表中
- [值] 需要重复
- theme_mods_my-theme 需要改成 theme_mods_my-new-theme
- 我猜 option_id 也需要更改,因为它是一个新插入。
解决方案
您可以使用插入选择而不是复制和更新,例如:
insert into mywpsite_18_options (col_theme_name, col2, col3 )
select 'theme_mods_my-new-theme', col2, col3
from mywpsite_18_options
where col_theme_name = 'theme_mods_my-theme'
但是您必须为每个表重新操作
推荐阅读
- css - CSS:即使我更改容器的大小,如何保持自定义弹出框和用于打开它的控件之间的距离
- r - R:重新列出非递归命名嵌套列表
- javascript - 从月份下拉选项中显示当前月份的 DIV
- flask - Python-dotenv 无法解析从第 2 行开始的语句
- javascript - 为什么我当前的 reactjs 项目在 package.json 脚本中包含这个“主题”:“lessc --js src/App.less src/App.css”?
- java - 我需要读取一个字符串并从中获取一个特定的值
- reactjs - ReactJs:如何在启动时选择性地加载反应功能组件?
- unity3d - 如何使用 SteamVR 开枪?
- javascript - 如何格式化日期时间字符串
- bash - 使 latexmk -pdf -pvc 在我的文档中间停止报告更改