当前位置:网站首页>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
边栏推荐
- There appears to be a failure with your network connection Retrying.
- Shardingsphere-proxy-5.0.0 establish MySQL read / write separation connection (6)
- 【历史上的今天】6 月 8 日:万维网之父诞生;PHP 公开发布;iPhone 4 问世
- STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动
- ROS+Gazebo中红绿黄交通灯如何实现?
- Step by step interpretation of crf+bilstm code
- OSI 7层模型讲解(大白话 通俗易懂)
- Explanation of OSI layer 7 model (easy to understand in Chinese)
- JS implementation of Slide Puzzle verification
- 「大道智创」获千万级preA+轮融资,推出科技消费机器人
猜你喜欢

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

数据治理与数据标准

如何以数据驱动「客户全生命周期管理」,提高线索转化率及客户满意度?

批阅2022春季学期课程小论文提交情况

迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比

【历史上的今天】6 月 3 日:微软推出必应搜索引擎;Larry Roberts 启动阿帕网;Visual Basic 之父出生

How does win11 add printers and scanners? Win11 add printer and scanner settings

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

【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形

How to realize red, green and yellow traffic lights in ros+gazebo?
随机推荐
Dynamic Host Configuration Protocol
JS implementation of Slide Puzzle verification
AAVE launches lens protocol, a Web3 social media platform
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
【历史上的今天】6 月 3 日:微软推出必应搜索引擎;Larry Roberts 启动阿帕网;Visual Basic 之父出生
Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
Teach you how to realize pynq-z2 bar code recognition
Wangxinling, tanweiwei Shanhai (extended version of Chorus) online audition lossless FLAC Download
Character interception triplets of data warehouse: substrb, substr, substring
SQL injection bypass (IV)
云平台kvm迁移本地虚拟机记录
Résumé de la graduation
Data governance and data standards
SQL reported an unusual error, which confused the new interns
Anonymous Mount & named mount
flask基础:模板继承+静态文件配置
Explanation of OSI layer 7 model (easy to understand in Chinese)
OSI 7层模型讲解(大白话 通俗易懂)
SQL injection bypass (3)
Flask基础:模板渲染+模板过滤使用+控制语句