MySQL入门 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

alter修改表结构


有时你可能需要改变一下现有表的结构,那么alter table语句将是你的合适选择。

增加列

alter table tbl_name add col_name type

例如增加一个weight列:

alter table test01_01 add weight int;

修改列

alter table test01_01 modify weight varchar(50);

删除列

alter table test01_01 drop weight;

另外一种常用方式,例如:

给列更名

alter table test01_01 change weight wei int;

给表更名

alter table test01_01 rename test01_04;
请选用test01数据库,为名为test01_01的数据表添加名为“sex”的列,类型varchar,查看结果,并且删除此列