当前位置:网站首页>MySQL进阶之数据的增删改查(DML)
MySQL进阶之数据的增删改查(DML)
2022-04-23 20:39:00 【小简(JanYork)】
增
INSERT INTO stu(studentNo, loginPwd, studentName, sex, gradeId, phone, address, bornDate, mail, identityCard) VALUE ('123456','00000','小简','秘密','1','1888888888','长沙','2000-1-1','[email protected]','43032000000000');
INSERT INTO 表名(字段1,字段2) VALUE (值1,值2);
-- 如非数值,请加上单引号,如:('值1','值2')
插入多行
INSERT INTO 表名(字段1,字段2) VALUE (值1,值2),(值1,值2);
-- 这样就可以一次插入多行
将查询的结果插入新表
格式1
INSERT INTO 表名(字段1,字段2) SELECT 字段1,字段2 FROM 原表名;
-- 使用方法和会出现的问题就不需要多说了,自行尝试
格式2
SELECT 字段1,字段2 INTO 新表名 FROM 原表名;
删
-- DELETE FROM 表名 WHERE [条件];
-- WHERE [条件]可以不写,不写就是无条件删除所有,有条件就是删除符合条件的!!!
DELETE FROM stu WHERE studentNo = '888888';
删除表中所有数据
-- TRUNCATE TABLE 表名;
TRUNCATE TABLE stu;
注意:使用此语句删除表中数据,将会重置自增列,并且执行效率优于DELETE
。
改
更新语句我们使用UPDATE
关键词。
-- UPDATE 表名 SET 字段名 = '字段值',字段名 = '字段值' WHERE [条件]
-- WHERE [条件]可以不写,不写就是无条件修改所有,有条件就是修改符合条件的!!!
UPDATE stu SET studentNo = '888888' WHERE studentNo = '123456';
查
SELECT * FROM stu WHERE studentNo = '888888';
这是一段简单的查询语句。同上,WHERE
可以省略,如果不要WHERE
条件,就是无条件查询所有。
我们还可以写复杂一点。
SELECT * FROM stu WHERE studentNo = '888888' GROUP BY studentNo ORDER BY studentNo ASC ;
我们分解,挨个瞧一瞧。
注:[ ]
内表示非必要语句。
SELECT *或<字段名列表> FROM <表名或视图> [WHERE <查询条件>] [GROUP BY 需要分组的字段] [ORDER BY 需要排序的字段 [ASC或DESC] ] ;
*
表示所有。FROM
后主要是接数据来源,可以单个也可以多个。WHERE
用于条件筛选。GROUP BY
可以让查询的数据根据指定字段分组。HAVING
用于筛选组,就是对于GROUP BY
分出的组进行筛选等等。ORDER BY
用于排序,根据某一列排序,ASC
是升序,DESC
是降序
版权声明
本文为[小简(JanYork)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_60750453/article/details/124326646
边栏推荐
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- Create vs project with MATLAB
- On IRP from the perspective of source code
- Leetcode 1351. Negative numbers in statistical ordered matrices
- [stack and queue topics] - sliding window
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- [latex] 5 how to quickly write out the latex formula corresponding to the formula
- Unity Odin ProgressBar add value column
- JSX syntax rules
- Solve the Chinese garbled code of URL in JS - decoding
猜你喜欢
UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
go-zero框架数据库方面避坑指南
On BIM data redundancy theory
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
Flex layout
Browser - learning notes
Es error: request contains unrecognized parameter [ignore_throttled]
Devexpress 14.1 installation record
Identification of bolt points in aerial photography based on perception
随机推荐
LeetCode 20、有效的括号
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
I JS deep copy and shallow copy
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom
Bash script learning -- for loop traversal
Experience of mathematical modeling in 18 year research competition
Use of node template engine
go array
Commit and rollback in DCL of 16 MySQL
Linux64Bit下安装MySQL5.6-不能修改root密码
Case of the third day of go language development fresh every day project - news release system II
[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
Syntaxerror: unexpected token r in JSON at position 0
Commande dos pour la pénétration de l'Intranet
Scripy tutorial - (2) write a simple crawler
How to do after winning the new debt? Is it safe to open an account online
BMP JPEG 图片转换为矢量图像 ContourTrace
【PTA】L1-002 打印沙漏
Preliminary understanding of cache elimination algorithm (LRU and LFU)