MySQL修改表结构--添加删除字段

MySQL修改表结构包含诸多的功能,下面介绍的MySQL修改表结构操作实现的是字段的添加及删除等,如果您对MySQL修改表结构方面感兴趣的话,不妨一看。

MySQL修改表结构--添加字段:

alter table `user_movement_log`
Add column GatewayId int not null default 0 AFTER `Regionid` (在哪个字段后面添加)

MySQL修改表结构--删除字段:

alter table `user_movement_log` drop column Gatewayid

调整字段顺序:

ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID

//主键

alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);

//增加一个新列

alter table t2 add d timestamp;
alter table infos add ex tinyint not null default ’0′;

//删除列

alter table t2 drop column c;

//重命名列

alter table t1 change a b integer;

//改变列的类型

alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default ’0′;

//重命名表

alter table t1 rename t2;

原文地址:https://www.cnblogs.com/txd66/p/3255064.html