ALTER TABLE
tbl_name
[alter_option
[,alter_option
] ...] [partition_options
]alter_option
: {table_options
| ADD [COLUMN]col_name
column_definition
[FIRST | AFTERcol_name
] | ADD [COLUMN] (col_name
column_definition
,...) | ADD {INDEX | KEY} [index_name
] [index_type
] (key_part
,...) [index_option
] ... | ADD {FULLTEXT | SPATIAL} [INDEX | KEY] [index_name
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] PRIMARY KEY [index_type
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] UNIQUE [INDEX | KEY] [index_name
] [index_type
] (key_part
,...) [index_option
] ... | ADD [CONSTRAINT [symbol
]] FOREIGN KEY [index_name
] (col_name
,...)reference_definition
| ADD [CONSTRAINT [symbol
]] CHECK (expr
) [[NOT] ENFORCED] | DROP {CHECK | CONSTRAINT}symbol
| ALTER {CHECK | CONSTRAINT}symbol
[NOT] ENFORCED | ALGORITHM [=] {DEFAULT | INSTANT | INPLACE | COPY} | ALTER [COLUMN]col_name
{ SET DEFAULT {literal
| (expr
)} | SET {VISIBLE | INVISIBLE} | DROP DEFAULT } | ALTER INDEXindex_name
{VISIBLE | INVISIBLE} | CHANGE [COLUMN]old_col_name
new_col_name
column_definition
[FIRST | AFTERcol_name
] | [DEFAULT] CHARACTER SET [=]charset_name
[COLLATE [=]collation_name
] | CONVERT TO CHARACTER SETcharset_name
[COLLATEcollation_name
] | {DISABLE | ENABLE} KEYS | {DISCARD | IMPORT} TABLESPACE | DROP [COLUMN]col_name
| DROP {INDEX | KEY}index_name
| DROP PRIMARY KEY | DROP FOREIGN KEYfk_symbol
| FORCE | LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE} | MODIFY [COLUMN]col_name
column_definition
[FIRST | AFTERcol_name
] | ORDER BYcol_name
[,col_name
] ... | RENAME COLUMNold_col_name
TOnew_col_name
| RENAME {INDEX | KEY}old_index_name
TOnew_index_name
| RENAME [TO | AS]new_tbl_name
| {WITHOUT | WITH} VALIDATION }partition_options
:partition_option
[partition_option
] ...partition_option
: { ADD PARTITION (partition_definition
) | DROP PARTITIONpartition_names
| DISCARD PARTITION {partition_names
| ALL} TABLESPACE | IMPORT PARTITION {partition_names
| ALL} TABLESPACE | TRUNCATE PARTITION {partition_names
| ALL} | COALESCE PARTITIONnumber
| REORGANIZE PARTITIONpartition_names
INTO (partition_definitions
) | EXCHANGE PARTITIONpartition_name
WITH TABLEtbl_name
[{WITH | WITHOUT} VALIDATION] | ANALYZE PARTITION {partition_names
| ALL} | CHECK PARTITION {partition_names
| ALL} | OPTIMIZE PARTITION {partition_names
| ALL} | REBUILD PARTITION {partition_names
| ALL} | REPAIR PARTITION {partition_names
| ALL} | REMOVE PARTITIONING }key_part
: {col_name
[(length
)] | (expr
)} [ASC | DESC]index_type
: USING {BTREE | HASH}index_option
: { KEY_BLOCK_SIZE [=]value
|index_type
| WITH PARSERparser_name
| COMMENT ‘string
‘ | {VISIBLE | INVISIBLE} }table_options
:table_option
[[,]table_option
] ...table_option
: { AUTOEXTEND_SIZE [=]value
| AUTO_INCREMENT [=]value
| AVG_ROW_LENGTH [=]value
| [DEFAULT] CHARACTER SET [=]charset_name
| CHECKSUM [=] {0 | 1} | [DEFAULT] COLLATE [=]collation_name
| COMMENT [=] ‘string
‘ | COMPRESSION [=] {‘ZLIB‘ | ‘LZ4‘ | ‘NONE‘} | CONNECTION [=] ‘connect_string
‘ | {DATA | INDEX} DIRECTORY [=] ‘absolute path to directory
‘ | DELAY_KEY_WRITE [=] {0 | 1} | ENCRYPTION [=] {‘Y‘ | ‘N‘} | ENGINE [=]engine_name
| ENGINE_ATTRIBUTE [=] ‘string
‘ | INSERT_METHOD [=] { NO | FIRST | LAST } | KEY_BLOCK_SIZE [=]value
| MAX_ROWS [=]value
| MIN_ROWS [=]value
| PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] ‘string
‘ | ROW_FORMAT [=] {DEFAULT | DYNAMIC | FIXED | COMPRESSED | REDUNDANT | COMPACT} | SECONDARY_ENGINE_ATTRIBUTE [=] ‘string
‘ | STATS_AUTO_RECALC [=] {DEFAULT | 0 | 1} | STATS_PERSISTENT [=] {DEFAULT | 0 | 1} | STATS_SAMPLE_PAGES [=]value
| TABLESPACEtablespace_name
[STORAGE {DISK | MEMORY}] | UNION [=] (tbl_name
[,tbl_name
]...) }partition_options
: (seeCREATE TABLE
options)
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] { {VALUES | VALUE} (value_list
) [, (value_list
)] ... | VALUESrow_constructor_list
} [ASrow_alias
[(col_alias
[,col_alias
] ...)]] [ON DUPLICATE KEY UPDATEassignment_list
] INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [ASrow_alias
[(col_alias
[,col_alias
] ...)]] SETassignment_list
[ON DUPLICATE KEY UPDATEassignment_list
] INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE] [INTO]tbl_name
[PARTITION (partition_name
[,partition_name
] ...)] [(col_name
[,col_name
] ...)] [ASrow_alias
[(col_alias
[,col_alias
] ...)]] {SELECT ... | TABLEtable_name
} [ON DUPLICATE KEY UPDATEassignment_list
]value
: {expr
| DEFAULT}value_list
:value
[,value
] ...row_constructor_list
: ROW(value_list
)[, ROW(value_list
)][, ...]assignment
:col_name
= [row_alias
.]value
assignment_list
:assignment
[,assignment
] ...
原文:https://www.cnblogs.com/ios9/p/14179518.html