当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL数据库列的增删改实现方法

MySQL数据库列的增删改实现方法

2019年03月19日  | 移动技术网IT编程  | 我要评论

本文实例讲述了mysql数据库列的增删改实现方法。分享给大家供大家参考,具体如下:

新建表user_info:

create table user_info(
id int not null primary key auto_increment,
username char(20) not null default '',
gender tinyint unsigned not null default 0,
weight tinyint unsigned not null default 0
)engine=myisam default charset=utf8;

新增列默认在表的最后一列

语法:alter table 表名 add 列名 列类型 列属性

alter table user_info add height tinyint unsigned not null default 0;

删除列

语法:alter table 表名 drop 列名

alter table user_info drop height;

增加列,放在指定列之后

语法:alter table 表名 add 列名 类型 属性 [默认值] after 指定列名

alter table user_info add height tinyint not null default 0 after username;

修改指定列名

语法:alter table 表名 change 旧列名 新列名 类型 属性 默认值

alter table user_info change height shengao smallint not null default 0;

modify 修改列,但不能修改列名

语法:alter table 表名 modify 列名 类型 属性 默认值

alter table user_info modify shengao tinyint not null default 0;

更多关于mysql相关内容感兴趣的读者可查看本站专题:《mysql常用函数大汇总》、《mysql日志操作技巧大全》、《mysql事务操作技巧汇总》、《mysql存储过程技巧大全》及《mysql数据库锁相关技巧汇总

希望本文所述对大家mysql数据库计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网