当前位置:网站首页>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.
案例

边栏推荐
- pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
- UE4 rays flashed from mouse position detection
- 云服务器下载安装mongo数据库并远程连接详细图文版本(全)
- 「以云为核,无感极速」顶象第五代验证码
- 用控件当画笔获得bitmap代码记录
- The Flow Of Percona Toolkit pt-table-checksum
- (2022牛客多校四)K-NIO‘s Sword(思维)
- 备战金九银十,如何顺利通过互联网大厂Android的笔面试?
- (2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)
- Error: AttributeError: module 'matplotlib' has no attribute 'figure'
猜你喜欢

SL-12/2过流继电器

typescript25 - type assertion

(2022牛客多校四)H-Wall Builder II(思维)

华为Android开发面试后得出的面试秘诀

PAT乙级 1002 写出这个数

这里有110+公开的专业数据集

(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)

干货!如何使用仪表构造SRv6-TE性能测试环境

(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)

Typescript20 - interface
随机推荐
Selenium:操作Cookie
可持久化线段树
The method of solving stored procedure table name passing through variable in mysql
SL-12/2过流继电器
Selenium:浏览器操作
Selenium:鼠标、键盘事件
USB3.0:VL817Q7-C0的LAYOUT指南(三)
typescript25 - type assertion
[MySQL] 多表查询
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
【云原生之kubernetes实战】kubernetes集群的检测工具——popeye
JWL-11/2-99.9A电流继电器
PAT serie b write the number 1002
Selenium:上传、下载文件
干货!如何使用仪表构造SRv6-TE性能测试环境
MySQL实践总结-
25. 这三道常见的面试题,你有被问过吗?
Error: AttributeError: module 'matplotlib' has no attribute 'figure'
DL-31/6电流继电器
RSA主要攻击方法