mysql alter用法场景
mysql 用法 场景 ALTER
2023-09-27 14:22:26 时间
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)设置字段允许为空
alter table sys_application modify column description varchar(255) null COMMENT '应用描述';
(4)增加一个字段,并设置数据类型,且不为空,添加注释
alter table sys_application add `url` varchar(255) not null comment '应用访问地址';
(5)增加主键
alter table t_app add aid int(5) not null,add primary key (aid);
(6)增加自增主键
alter table t_app add aid int(5) not null auto_increment ,add primary key (aid);
(7)修改为自增主键
alter table t_app modify column aid int(5) auto_increment ;
(8)修改字段名字(要重新指定该字段的类型)
alter table t_app change name app_name varchar(20) not null;
(9)删除字段
alter table t_app drop aid;
(10)在某个字段后增加字段
-- 在哪个字段后面添加
alter table `t_app` add column gateway_id int not null default 0 AFTER `aid`;
(11)调整字段顺序
-- 注意gateway_id出现了2次
alter table t_app change gateway_id gateway_id int not null after aid ;
相关文章
- mysql greatest的用法_SQL GREATEST()函数实例详解实例
- mysql 然后根据关键字进行匹配,根据匹配度高低进行排序
- <转>MySQL临时表的简单用法
- mysql之TIMESTAMP(时间戳)用法详解
- mysql通过sql来复制表结构
- mysql的视图
- MySQL 里面的Where 和Having和Count 和distinct和Group By对比
- mysql中case when then end的含义和用法
- SQL学习笔记之MySQL查询练习2
- mysql merge update_SQL中批量更新 merge into用法
- C#简单构架之EF进行读写分离+多数据库Mysql/SqlServer
- 用if写一个备份mysql的脚本
- Mysql 临时变量的 定义 和 赋值 Set 和 Into 赋值; Swith Mysql版本 Case When的用法
- LocalDateTime与mysql日期类型的交互(基于mybatis)
- mysql 中 DATE_ADD函数和 DATE_SUB函数用法
- mysql行锁和表锁
- mysql LIMIT 子句用法及原理
- mysql操作查询结果case when then else end用法举例
- MySQL 存储过程传参之in, out, inout 参数用法
- MySQL 中间件汇总比较
- MySQL的安装与配置
- MySql 里的IFNULL、NULLIF和ISNULL用法
- 关于MySQL里的found_row()和row_count()解释及用法 [复制链接]
- mysql explain用法
- mysql同步之otter/canal环境搭建完整详细版
- Mysql中REPLACE INTO用法,判断数据是否存在,如果不存在,则插入,如果存在,则先删除此行数据,然后插入新的数据
- mysql limit和offset用法
- MySQL:连接查询 | 内连接,外连接
- 【mysql】累计病例数(从10,000例起的天数)