当前位置: Oracle DBA培训网-优技培训 >> MySQL培训 > MySQL培训教程 >

MySQL培训课程:alter语句修改表的结构

MySQL培训课程:alter语句修改表的结构

MySQL培训课程:alter语句修改表的结构,有时你可能需要改变一下现有表的结构,那么Alter Table语句将是你的合适选择。

增加列

alter table tbl_name add col_name type

例如,给表增加一列weight

mysql>alter table pet add weight int;

删除列

alter table tbl_name drop col_name

例如,删除列weight:

mysql>alter table pet drop weight;

改变列

alter table tbl_name modify col_name type

例如,改变weight的类型:

mysql> alter table pet modify weight samllint;

另一种方法是:

alter table tbl_name change old_col_name col_name type

例如:

mysql> alter table pet change weight weight samllint;

给列更名

mysql>alter table pet change weight wei;

给表更名

alter table tbl_name rename new_tbl

例如,把pet表更名为animal

mysql>alter table pet rename animal;

改变表的类型

另外,可以为列增加或删除索引等属性,不再详述,请参阅附录。

技术沙龙MORE+

Oracle技术沙龙:【数据保护顶尖技术-MAA】首次全国首播12c MAA技术 云数据库加上MAA技术组成最豪华的技...
Oracle技术沙龙第49期:【Oracle 数据库云技术分享】Oracle技术沙龙第49期:【Oracle 数据库云技术分享】本次技术沙...
Oracle技术沙龙第48期:【Oracle 12c RAC安装】小编:今天讲什么内容呢?以后有什么用呢? 大师:今天讲的是12c...
我要参加技术沙龙