重命名mysql表中的列,而不必重复其类型定义 [英] Rename a column in mysql table without having to repeat its type definition
问题描述
是否可以在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
orMODIFY
, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such asPRIMARY KEY
orUNIQUE
. Attributes present in the original definition but not specified for the new definition are not carried forward.
这篇关于重命名mysql表中的列,而不必重复其类型定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!