MySQL 在单个语句中更改多个列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10846499/
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 13:36:12  来源:igfitidea点击:

Alter multiple columns in a single statement

mysqlsqlmysql-error-1064alter-table

提问by Sangram Anand

I am using a query to alter the charset of a column

我正在使用查询来更改列的字符集

ALTER TABLE `media_value_report` 
    CHANGE `index_page_body` `index_page_body` TEXT CHARACTER  
    SET utf8 NULL DEFAULT NULL

i want to do this for other columns main_title, landing_page_body as well. But am getting a #1064 error while executing. Can i alter-change multiple columns in a single query?

我也想对其他列 main_title、landing_page_body 执行此操作。但是在执行时出现 #1064 错误。我可以在单个查询中更改多个列吗?

I tried but i found in goog search that is not possible to alter in a single query.

我尝试过,但我在 goog 搜索中发现无法在单个查询中进行更改。

回答by Andomar

The documentation suggestsyou can chain alter_specifications with a comma:

文档建议您可以使用逗号链接 alter_specifications:

ALTER TABLE `media_value_report` 
    CHANGE col1_old col1_new varchar(10),
    CHANGE col1_old col1_new varchar(10),
    ...