当前位置:网站首页>MySQL-DML language-database operation language-insert-update-delete-truncate
MySQL-DML language-database operation language-insert-update-delete-truncate
2022-08-01 05:04:00 【LXMXHJ】
文章目录
DML概述
介绍
主要包括 插入insert、更新update、删除delete
语法总结
insert into 表名(列1,列2....)
values (值1,值2.....)
update 表1 别名1 表2 别名2
set 列 = 值, 列 = 值...
on 连接条件
where 筛选条件;
delete 别名1 ,别名2
from 表1 别名1,表2 别名2
on connection price adjustment
where 筛选条件;
插入语句insert into
方式1:经典插入
概述
语法
insert into 表名(列名,......)
values(值1,......)
注意事项
插入的值的类型要与列的类型一致或兼容.兼容性说明:
If the field isint类型,但是输入的是‘123’这样是不会报错的,The reason is that this char type can be implicitly converted to a number.
If you get it‘join’,则不可行.
不可以为null的列必须插入值,可以为nullColumns can insert values in two ways as follows
字段的个数和顺序不一定与原始表中的字段个数和顺序一致,但是插入valuesOne-to-one correspondence with the column field order
列数和值的个数必须一致,否则会报错
可以省略字段名,默认插入所有列,And the order of the columns is the same as the order of the fields in the table
方式2
概述
语法
insert into 表名
set 列名 = 值 , 列名 = 值......
案例
方式1与方式2 区别
方式1支持多行插入,方式2不支持
# 方式1:
insert into 表名 (列名1,列名2.....)
values (值1,值2,......),
(值1,值2,.......);
案例:
方式1支持子查询,方式2不支持
insert into 表名(字段1,字段2,...)
查询语句;
案例
修改语句update
概述
- 修改单表的记录
语法
update 表名
set 字段 = 新值,字段 = 新值....
[where 筛选条件];
- 修改多表记录
语法sql92
update 表1 别名,表2 别名
set 列 = 值, 列 = 值...
where 连接条件
and 筛选条件;
语法sql99
update 表1 别名
[inner | left | right ] join 表2 别名
on 连接条件
where 筛选条件;
案例
单表修改
多表修改
删除语句delete 和 truncate
方式1:delete
概述
- 单表删除
语法
delete from 表名
where 筛选条件
[limit 条目数];
- 多表的删除
语法sql92
delete 别名1,别名2
from 表1 别名1,表2 别名2
where 连接条件
and 筛选条件;
语法sql99
delete 别名1.别名2
from 表1 别名1
[inner | left |right ] join 表2 别名2
on 连接条件
where 筛选条件;
注意
delete后面的别名,Depends on which table information is being dropped.
案例
方式2:truncate
语法
truncate table 表名;
作用
Mainly used to delete the information of the entire table
delete 和 truncate区别
区别 | delete | truncate |
---|---|---|
where条件 | 可加 | 不可加 |
效率 | 略差 | 较高 |
删除自增长列 | 删除再插入,自增长列的值从断点开始 | Delete and insert data,Self-growing columns start from scratch(即1) |
删除内容 | 可以删除部分记录 | 删除全部记录,But the table is not dropped |
– | 扩展 | drop 删除整张表 |
返回值 | 有返回值 返回删除的行数 | 没有返回值 |
回滚 | 可以回滚 | 不可以回滚 |
高水线 | Does not affect the high water line | 会将高水线复位 |
扩展2022/7/31
所有的segments段(segment作为表的一个同义词) Both have one in the segment The upper limit to hold the data,This is the high water line(High Water Mark).这个HWM是一个标记,用来说明已经有多少没有使用的数据块分配给这个segment.
HWM通常增长的幅度为一次5个数据块,原则上HWM只会增大,不会缩小,即使将表中的数据全部删除,HWM还是为原值.
打个比方,HWMMuch like the all-time high water level of a reservoir,There is currently no water in the reservoir,It cannot be stated that the historical highest water level of the reservoir is0;
但是如果我们在表上使用了truncate命令,则该表的HWM会被重新置为0.
案例
边栏推荐
- (2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
- API设计笔记:pimpl技巧
- 56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
- 请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
- typescript24-类型推论
- Selenium:元素等待
- High Numbers | 【Re-integration】Line Area Score 880 Examples
- MySQL Practice Summary -
- 万字逐行解析与实现Transformer,并进行德译英实战(三)
- TIM登陆时提示00001(TIM00001)
猜你喜欢
随机推荐
万字逐行解析与实现Transformer,并进行德译英实战(一)
【目标检测】YOLOv7理论简介+实践测试
safari浏览器怎么导入书签
state compressed dp
PMP 相关方管理必背总结
mysql中解决存储过程表名通过变量传递的方法
零序电流继电器器JL-8C-12-2-2
挑战52天背完小猪佩奇(第01天)
请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
MySQL实践总结-
Typescript20 - interface
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (2)
【堆】小红的数组
PAT乙级 1002 写出这个数
PMP 项目质量管理
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
The method of solving stored procedure table name passing through variable in mysql
Typescript22 - interface inheritance
PMP 项目沟通管理
LeetCode 27. 移除元素