当前位置:网站首页>Mysql database foundation: DML data operation language
Mysql database foundation: DML data operation language
2022-06-28 02:44:00 【Long lasting bangbangjun】
DML Language
1、insert Insert statement
grammar
- The first way : Classic insertion
insert into Table name ( Name 1, Name 2,...) values ( value 1, value 2,...)
Be careful :
1、 The type of the inserted value should be consistent with or compatible with the type of the column
2、 Not for null The column of must have a value inserted , It can be for null The column of (nullable) Either null Insert as value , Or you can omit the column and the corresponding value of the column at the same time .
3、 The order of columns can be reversed , But the corresponding value should also be matched and exchanged
4、 The number of columns and the number of values must be the same
5、 You can omit column names , But the order of the columns should be consistent with that of the columns in the table , And the value of null Of cannot be omitted
- The second way
insert into Table name
set Name = value , Name = value ,...
Compare the two insertion methods
1、 Method 1 can support inserting multiple rows , The way 2 I won't support itinsert into Table name values ( value 1, value 2,...) ,( value 1, value 2,...) ,( value 1, value 2...);2、 Mode 1 supports subquery , Method 2 does not support sub query
insert into Table name ( Name 1, Name 2,...) select sentenceSo mode 1 uses more scenarios
2、update to update / Modify the statement
2.1 Record of modification list
- grammar
update Table name
set Column = The new value , Column = The new value ,...
where filter ;
- example
# modify beauty The phone number of the girl surnamed Tang in the table is 13887888881
update beauty set phone = '13887888881'
where name like ' The tang dynasty %';
# modify boys In the table id Number is 2 My name is Zhang Fei , Age is 22
update boys set name = ' Zhang Fei ',age = 22
where id = 2;
2.2 Modify multi table records
- grammar
update surface 1 Alias
inner|left|right join surface 2 Alias
on Connection condition
set Column = value ,...
where filter
- Case study
# Change Zhang's girlfriend's cell phone number to 114
update boys b
inner join beauty b
on bo.`id`=b.`boyfrind_id`
set b.`phone`='114'
where bo.`boyName`=' zhang wuji ';
3、delete/truncate Delete statements
grammar
- delete sentence
effect : Delete data from table
1、 Delete single table
# Delete all data in the table
delete from Table name ;
# Delete the data of the specified condition in the table
delete from Table name where filter ;
Example :
# Delete the phone number to 9 Girl's message at the end
delete from beauty where phone like '%9';
2、 Delete multiple tables
# Delete Zhang Wuji's girlfriend's information
delete surface 1 Another name for , surface 2 Another name for
from surface 1, surface 2
inner|left|right join surface 2 Alias
on Connection condition
where filter ;
Example :
# Delete Zhang Wuji's girlfriend's information
delete b
from beauty b
inner join boys bo
on b.`boyfriend_id`=bo.`id`
where bo.`boyName`=' zhang wuji ';
- truncate sentence
effect : Delete all data in the table
truncate table Table name ;
delete and truncate The difference between sentences
1、delete You can add where Conditions ,truncate Cannot add
2、truncate Delete efficiency ratio delete high
3、 If the table to be deleted has a self growing column , If you use delete After deleting , Then insert the data , The value of the self growing column starts at the breakpoint , and truncate After deleting , Then insert the data , The value of the self growing column starts from 1 Start
4、truncate Delete has no return value ,delete Delete with return value
5、truncate Deletion cannot be rolled back ,delete Delete can be rolled back
边栏推荐
- Complex and inefficient logistics? Three steps to solve problems in enterprise administration
- Teach you how to realize pynq-z2 bar code recognition
- MySQL query related knowledge (advanced level 7: sub query
- ROS+Gazebo中红绿黄交通灯如何实现?
- 【方块编码】基于matlab的图像方块编码仿真
- Redis~geospatial (geospatial), hyperloglog (cardinality Statistics)
- JS implementation of Slide Puzzle verification
- Flutter 使用 CustomPaint 绘制基本图形
- Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法
- Cvpr22 collected papers | hierarchical residual multi granularity classification network based on label relation tree
猜你喜欢

【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生

Design e-commerce seckill system

What if win11 can't drag an image to the taskbar software to open it quickly

Interpretation of bilstm-crf in NER forward_ algorithm

数据清洗工具flashtext,效率直接提升了几十倍数

【历史上的今天】6 月 1 日:Napster 成立;MS-DOS 原作者出生;谷歌出售 Google SketchUp

《低代码解决方案》——覆盖工单、维修和财务全流程的数字化售后服务低代码解决方案

【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播

Use code binding DataGridView control to display tables in program interface

win11如何添加打印机和扫描仪?win11添加打印机和扫描仪的设置
随机推荐
AAVE launches lens protocol, a Web3 social media platform
数仓的字符截取三胞胎:substrb、substr、substring
SQL报了一个不常见的错误,让新来的实习生懵了
JS implementation clock
[JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
Résumé de la graduation
Skills in schematic merging
Protocole de transfert de fichiers - - FTP
设计电商秒杀系统
MySQL optimization tips
云原生(三十) | Kubernetes篇之应用商店-Helm
Shuttle uses custompaint to paint basic shapes
【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
《低代码解决方案》——覆盖工单、维修和财务全流程的数字化售后服务低代码解决方案
A set of sai2 brushes is finally finished! Share with everyone!
如何以数据驱动「客户全生命周期管理」,提高线索转化率及客户满意度?
A low-cost method to increase private domain traffic with simple maintenance
Wangxinling, tanweiwei Shanhai (extended version of Chorus) online audition lossless FLAC Download
MySQL collection, here are all the contents you want
【历史上的今天】5 月 29 日:共享软件先驱诞生;ChromeBox 推出;VoodooPC 创始人出生