600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > mysql数据库表增加 删除 修改字段

mysql数据库表增加 删除 修改字段

时间:2018-08-02 00:57:42

相关推荐

mysql数据库表增加 删除 修改字段

在工作中,经常需要对表结构进行变更,对某些表添加字段、删除字段、修改某个字段的属性,常用的语句如下:

1:建表语句:

create table student (id bigint not null auto_increment COMMENT '主键',student_no bigint not null comment '学号',phone_no varchar(20) default null comment '电话号码',address varchar(100) default null comment '地址',PRIMARY KEY (id),index (student_no))

2:表增加一个字段:

alter table student add column student_name VARCHAR(20) default null COMMENT '名字';

3:表增加多个字段:

alter table student add column sex char(1) default null COMMENT '性别',add column age int default null comment '年龄';

4:删除某个字段:

alter table student drop column age;

5:修改某个字段:

alter table student modify column student_name varchar(50) default null comment '名字';

只有不断的学习才能遇见更好的自己,加油,美好的风景一直在路上。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。