基本語法:alter [online | offline] [ignore] table
tbl_name
[
alter_specification
[,alter_specification
] ...][
partition_options
]
alter_specification
:
table_options
| add [column]
col_name
column_definition
[first | after
col_name
]| add [column] (
col_name
column_definition
,...)| add [
index_name
][
index_type
] (index_col_name
,...) [index_option
] ...| add [constraint [
symbol
]] primary key[
index_type
] (index_col_name
,...) [index_option
] ...| add [constraint [
symbol
]]unique [index|key] [
index_name
][
index_type
] (index_col_name
,...) [index_option
] ...| add fulltext [index|key] [
index_name
](
index_col_name
,...) [index_option
] ...| add spatial [index|key] [
index_name
](
index_col_name
,...) [index_option
] ...| add [constraint [
symbol
]]foreign key [
index_name
] (index_col_name
,...)
reference_definition
| alter [column]
col_name
| change [column]
old_col_name
new_col_name
column_definition
[first|after
col_name
]| modify [column]
col_name
column_definition
[first | after
col_name
]| drop [column]
col_name
| drop primary key
| drop
index_name
| drop foreign key
fk_symbol
| disable keys
| enable keys
| rename [to|as]
new_tbl_name
| order by
col_name
[,col_name
] ...| convert to character set
charset_name
[collatecollation_name
]| [default] character set [=]
charset_name
[collate [=]collation_name
]| discard tablespace
| import tablespace
| force
| add partition (
partition_definition
)| drop partition
partition_names
| truncate partition
| coalesce partition
number
| reorganize partition [
partition_names
into (partition_definitions
)]| analyze partition
| check partition
| optimize partition
| rebuild partition
| repair partition
| partition by
partitioning_expression
| remove partitioning
index_col_name
:
col_name
[(length
)] [asc | desc]
index_type
:using
index_option
:key_block_size [=]
value
|
index_type
| with parser
parser_name
| comment '
string
'
table_options
:
table_option
[[,]table_option
] ... (seecreate table
options)
partition_options
:(see
create table
options)其中
table_options:包括
engine,row_format,auto_increment,character set,commentauto_increment 可以表示當前自動增長的值,comment表示表的注釋。
× 在大多數執行atler table語句的時候,資料庫都會建立乙個臨時的表,它是舊表的乙個輔助,資料庫會等待所有的其他操作完成以後才講對錶的更變加入到臨時表中。
× 在alter table 語句執行的時候,表仍然是可讀的,但是所有對錶的更新與寫操作都會被阻塞,知道新錶被準備好。
× 有些atler table的操作不會阻塞乙個表,對錶中列進行重新命名不會阻塞表。
× 對錶的元資料的修改不會導致表的複製:比如對錶的重新命名,列預設值的修改,還有就是增加乙個列舉成員等等。
alter table
withadd partition
,drop partition
,coalesce partition
,rebuild partition
, orreorganize partition
does not create any temporary tables (except when used withndb
tables);however, these operations can and do create temporary partition files.
Mysql alter常見使用語句
新增主鍵 alter table tabelname add new field id int 5 unsigned default 0 not null auto increment add primary key new field id 增加乙個新列 alter table rpt fmp e...
MySQL Alter語句 運用
修改表名 mysql alter table student rename person 這裡的student是原名,person是修改過後的名字 用rename來重新命名,也可以使用rename to 修改欄位的資料型別 mysql alter table person modify name v...
Mysql alter語句的用法
1 刪除列 alter table 表名字 drop 列名稱 2 增加列 alter table 表名字 add 列名稱 int not null comment 注釋說明 3 修改列的型別資訊 alter table 表名字 change 列名稱 新列名稱 這裡可以用和原來列同名即可 bigint...