以下的文章主要讲述的是MySQL表修改,即,增加或是删减列与创建或取消索引等相关操作,我们大家都知道MySQL在创建一个相关的数据库后,如果接着继续创建一张表而且加如了一些字段,那么我以后还想再增加字段怎么做?
解答:使用alter table(修改表)!
ALTER TABLE语法:
- ALTER [IGNORE] TABLE tbl_name
- alter_specification [, alter_specification] ...
- alter_specification:
- ADD [COLUMN] column_definition [FIRST | AFTER col_name ]
- | ADD [COLUMN] (column_definition,...)
- | ADD INDEX [index_name] [index_type] (index_col_name,...)
- | ADD [CONSTRAINT [symbol]]
- PRIMARY KEY [index_type] (index_col_name,...)
- | ADD [CONSTRAINT [symbol]]
- UNIQUE [index_name] [index_type] (index_col_name,...)
- | ADD [FULLTEXT|SPATIAL] [index_name] (index_col_name,...)
- | ADD [CONSTRAINT [symbol]]
- FOREIGN KEY [index_name] (index_col_name,...)
- [reference_definition]
- | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
- | CHANGE [COLUMN] old_col_name column_definition
- [FIRST|AFTER col_name]
- | MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
- | DROP [COLUMN] col_name
- | DROP PRIMARY KEY
- | DROP INDEX index_name
- | DROP FOREIGN KEY fk_symbol
- | DISABLE KEYS
- | ENABLE KEYS
- | RENAME [TO] new_tbl_name
- | ORDER BY col_name
- | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
- | [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
- | DISCARD TABLESPACE | IMPORT TABLESPACE | table_options
- | partition_options
- | ADD PARTITION partition_definition
- | DROP PARTITION partition_names
- | COALESCE PARTITION number
- | REORGANIZE PARTITION partition_names INTO (partition_definitions)
- | ANALYZE PARTITION partition_names
- | CHECK PARTITION partition_names
- | OPTIMIZE PARTITION partition_names
- | REBUILD PARTITION partition_names
- | REPAIR PARTITION pa
以上的相关内容就是对MySQL表修改的介绍,望你能有所收获。
【编辑推荐】