Rename a column in mysql table without having to repeat its type definition

前端 未结 2 1538
春和景丽
春和景丽 2021-02-19 02:44

Is it possible to rename a column in MySQL without having to repeat its type definition?

Please without having to hack into information_schema.

2条回答
  •  萌比男神i
    2021-02-19 03:15

    The ALTER TABLE syntax does not seem to offer such possibility:

    ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
        [alter_specification [, alter_specification] ...]
        [partition_options]
    
    ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
        partition_options
    
    alter_specification:
        table_options
    [...]
      | CHANGE [COLUMN] old_col_name new_col_name column_definition
            [FIRST|AFTER col_name]
      | MODIFY [COLUMN] col_name column_definition
            [FIRST | AFTER col_name]
    [...]
    

    More specifically:

    When you use CHANGE or MODIFY, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward.

提交回复
热议问题