回顾建表语句
create table 表名 (
列名称 列类型 [列属性] [默认值], //例如primary key auto_increment
列名称 列类型 [列属性] [默认值], //建表就是一个列声明的过程
列名称 列类型 [列属性] [默认值],
);
先说修改表名:
alter table 表名 rename 新表名;
增加列:
alter table 表名 add 列声明;
例如:alter table boy add height tinyint unsigned not null default 149;
增加列默认在表的最后一列。
如果想要声明新增的列在哪一列后面,可以用after。如果新增的列放在最前面,可以用first。
alter table boy add age tinyint unsigned not null default 22 after flower; 如下,新增的age列就在flower列后面了。
修改列:
alter table 表名 change 旧列名 新列声明;
比如:
alter table boy change height height smallint not null default 180; #把height的属性改为smallint
或者:
alter table test modify address char(10)
alter table test change column address address1 varchar(30)--修改表列名
删除列:
alter table 表名 drop 列名;
比如:
alter table boy drop height; #height列就会被删除掉