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

        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 '名字';

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


版权声明:本文为qq_36833673原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_36833673/article/details/128438125