mysql学习--表列的增删改

  1. 删除表的某一列
alter table class1
drop snum;

在这里插入图片描述

  1. 增加列

2.1 增加的列在最后面

alter table class1
add snum tinyint not null default 0;

在这里插入图片描述
2.2 把新列增加到某一列的后面

alter table class1
add birth date not null default '1000-01-01' after gender;

在这里插入图片描述
2.3新建一个列放到表的最前面

alter table class1
add pid int not null default 0 first;

在这里插入图片描述
3、修改列类型

alter table class1
modify gender char(4) not null default '';

在这里插入图片描述
4、修改列名称&列类型

alter table class1
change id uid int unsigned not null default 0;

在这里插入图片描述
注意:如果说改变列的类型,把存储范围大的列类型改为小的列类型,会出现数据丢失的情况,或者在MySQL严格模式下,根本修改不了。

发布了20 篇原创文章 · 获赞 0 · 访问量 233

猜你喜欢

转载自blog.csdn.net/alyssa_yu/article/details/104722482
今日推荐