Search code examples
mysqlsqlmysql-error-1064alter-table

Alter multiple columns in a single statement


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?

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


Solution

  • The documentation suggests you can chain alter_specifications with a comma:

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