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