重命名mysql表中的列,而不必重复其类型定义 [英] Rename a column in mysql table without having to repeat its type definition

查看:125
本文介绍了重命名mysql表中的列,而不必重复其类型定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在MySQL中重命名一列而不必重复其类型定义?

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

请不必入侵information_schema。

Please without having to hack into information_schema.

推荐答案

ALTER TABLE语法似乎没有提供这种可能性:

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]
[...]

更具体地说


当您使用 CHANGE MODIFY 时,column_definition必须包含数据
类型以及应应用于新列的所有属性,除索引属性以外的其他
,例如 PRIMARY KEY UNIQUE 。原始定义中存在但未为新的
定义指定的属性
不会结转。

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.

这篇关于重命名mysql表中的列,而不必重复其类型定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆