mysql alter 用法,修改表,字段等信息
一: 修改表信息
1.修改表名
alter table test_a rename to sys_app;
2.修改表注释
alter table sys_application comment '系统信息表';
二:修改字段信息
1.修改字段类型和注释
alter table sys_application modify column app_name varchar(20) COMMENT '应用的名称';
2.修改字段类型
alter table sys_application modify column app_name text;
3.单独修改字段注释
目前没发现有单独修改字段注释的命令语句。
4.设置字段允许为空
alter table sys_application modify column description varchar(255) null COMMENT '应用描述';
5.增加一个字段,设好数据类型,且不为空,添加注释
alter table sys_application add `url` varchar(255) not null comment '应用访问地址';
6.增加主键
alter table t_app add aid int(5) not null ,add primary key (aid);
7.增加自增主键
alter table t_app add aid int(5) not null auto_increment ,add primary key (aid);
8.修改为自增主键
alter table t_app modify column aid int(5) auto_increment ;
9.修改字段名字(要重新指定该字段的类型)
alter table t_app change name app_name varchar(20) not null;
10.删除字段
alter table t_app drop aid;
11.在某个字段后增加字段
alter table `t_app` add column gateway_id int not null default 0 AFTER `aid`; #(在哪个字段后面添加)
12.调整字段顺序
alter table t_app change gateway_id gateway_id int not null after aid ; #(注意gateway_id出现了2次)
分类:
Mysql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!