Summary of Mysql DML operations (INSERT, UPDATE, DELETE)

DML language

Explanation

DML is the abbreviation of Data Manipulation Language, which means data manipulation language. It refers to the instruction set responsible for running data access and work on database objects in the SQL language. It takes INSERT, UPDATE, and DELETE as the core instructions, which represent insert, Updates and deletions are instructions that must be used to develop data-centric applications.

understanding

DML language is standing on the data level
INSERT (insert) to insert data into the table.
UPDATE (update) updates the data in the table.
DELETE (delete) delete the data in the table.
(I have a little opinion, if you have any mistakes or problems, please leave a message in the comment area, or private chat)
Attach the beauty form and the boys form

beauty table:
Insert picture description hereboys table:
Insert picture description here

One, insert (INSERT)

Way one :

语法:
INSERT INTO 表名(列名1,列名2,列名3,...VALUES(值1,2,3,...;

#例:往beauty表中插入值
INSERT INTO beauty(id,NAME,sex,borndate,phone,photo,boyfriend_id)
VALUES(13,'唐艺昕','女','1990-4-23','123465',NULL,2);

Method one supports multi-line insertion:

#例:往beauty表中插入多行值
INSERT INTO beauty
VALUES(14,'唐艺昕1','女',null,'1313',NULL,2)
,(23,'唐艺昕2','女',null,'1313',NULL,2)
,(33,'唐艺昕3','女',null,'1313',NULL,2);

Also supports subquery insertion

#例:往beauty表中插入查找值
INSERT INTO beauty(id,NAME,phone)
SELECT 26,'宋茜','111082';

Note: The
data source select statement can be written in many ways. Note: The number, order, and type of the fields returned by the select and the inserted data must be consistent.

Way two :

INSERT INTO 表名
SET 列名1=1,列明2=2;

#例:往beauty表中插入值
INSERT INTO beauty
SET id=19,name ='刘涛',phone='999';

Method two does not support multi-row insertion and subquery insertion.

Second, modify (UPDATE)

There are two ways to modify: one is single-table modification, and the other is multi-table modification.

1. Single table modification

语法:
UPDATE 表面
SET 列名1=新值1,列名2=新值2 ....
WHERE 筛选条件;

#例:修改beauty表中性唐的女神的电话为13899988899
UPDATE beauty
SET phone='13899988899'
WHERE NAME LIKE '唐%'

2. Multi-table modification

There are two standards for multi-table modification:
SQL92 standard
SQL99 standard

#sql92语法:
UPDATE1 别名,表2 别名
SET列名1=新值1,列名2=新值2 ....
WHERE 连接条件
AND 筛选条件;

#例:修改张无忌的女朋友的手机号为114
UPDATE boys bo,beauty be
SET phone='114'
WHERE bo.id=be.boyfriend_id
AND boyName='张无忌';

#sql99语法
UPDATE 表一 别名
INNER||LEFT||RIGHT JOIN2 别名
ON 连接条件
set 列名1=新值1,列名2=新值2 ....
WHERE 筛选条件;

#例:修改张无忌的女朋友的手机号为114
UPDATE boys bo
INNER JOIN beauty be
ON bo.id=be.boyfriend_id
SET phone='114'
WHERE boyName='张无忌';

Three, delete (DELETE)

There are three ways to delete: the
first one: single table delete.
The second type: delete multiple tables.
The third type: TRUNCATE deletes all the data in the entire table, and only retains the structure of the table, but TRUNCATE does not belong to the DML language and belongs to the DDL language. (Use with caution)

1. Single table delete

#语法:
DELETE FROM 表名 WHERE 筛选条件

#例:删除手机号以9结尾的女神信息
DELETE FROM beauty WHERE phone LIKE '%9';

2. Delete multiple tables

There are two standards for deleting multiple tables:
SQL92 standard
SQL99 standard

#sql92语法:
DELETE1的别名
FROM1 别名,表2 别名
WHERE 连接条件
AND 筛选条件;
#例:删除张无忌的女朋友信息
DELETE b
FROM beauty b,boys bo
WHERE b.boyfriend_id=bo.id
AND bo.boyName='张无忌';

#sql99语法:
DELETE1的别名
FROM1 别名
INNER||LEFT||RIGHT JOIN2 别名
ON 连接条件
WHERE 筛选条件;
#例:删除张无忌的女朋友信息
DELETE b
FROM beauty b
INNER JOIN boys bo
ON b.boyfriend_id=bo.id
WHERE bo.boyName='张无忌';

3,TRUNCATE

#语法:
TRUNCATE TABLE 表名

#例:清空boys表
TRUNCATE TABLE boys;

Guess you like

Origin blog.csdn.net/Clanno/article/details/114077061