IT技术网www.itjs.cn

当前位置:首页 > 数据库 > MySQL > MySQL修改表结构--添加删除字段

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

发布时间:2010-10-13 10:03 来源:未知

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;