当前位置:网站首页>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
边栏推荐
- 【PTA】L2-011 玩转二叉树
- Introduction to intrusion detection data set
- MySQL 存储过程和函数
- [PTA] l1-006 continuity factor
- ABAQUS script email auto notification
- [latex] 5 how to quickly write out the latex formula corresponding to the formula
- [graph theory brush question-4] force deduction 778 Swimming in a rising pool
- How can matlab obtain the truncated image in trainingimagelabeler
- ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
- LeetCode 994、腐烂的橘子
猜你喜欢
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
Recognition of high-speed road signs by Matlab using alexnet
【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
go slice
Unity Odin ProgressBar add value column
2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
A login and exit component based on token
内网渗透之DOS命令
Commit and ROLLBACK in DCL of 16mysql
[PTA] l1-002 printing hourglass
随机推荐
16MySQL之DCL 中 COMMIT和ROllBACK
The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
Unity solves Z-fighting
MySQL 存储过程和函数
Flex layout
Parsing methods of JSON data in C - jar and jobobject: error reading jar from jsonreader Current JsonReader item
How do BIM swindlers cheat? (turn)
2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
LeetCode 116. Populate the next right node pointer for each node
DOS command of Intranet penetration
Resolve the error - error identifier 'attr_ id‘ is not in camel case camelcase
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
Communication between RING3 and ring0
2021-06-29 C escape character cancellation and use
Use of node template engine
Learn to C language fourth day
Leetcode 542, 01 matrix
Queue template code
[PTA] get rid of singles
LeetCode 542、01 矩阵