当前位置:网站首页>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
边栏推荐
- LeetCode 1351、统计有序矩阵中的负数
- Some basic knowledge of devexpress report development
- Implementation of mypromise
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- Historical track data reading of Holux m1200-e Bluetooth GPS track recorder
- go-zero框架数据库方面避坑指南
- bounding box iou
- Unity asset import settings
- Customize timeline component styles
- Recognition of high-speed road signs by Matlab using alexnet
猜你喜欢
Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom
DOS command of Intranet penetration
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
The ODB model calculates the data and outputs it to excel
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
Linux64Bit下安装MySQL5.6-不能修改root密码
On BIM data redundancy theory
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
Commit and ROLLBACK in DCL of 16mysql
随机推荐
LeetCode 1351、统计有序矩阵中的负数
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
ABAQUS script email auto notification
LeetCode 116. Populate the next right node pointer for each node
CONDA environment management command
Parsing methods of JSON data in C - jar and jobobject: error reading jar from jsonreader Current JsonReader item
How many hacking methods do you know?
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam
On BIM data redundancy theory
【栈和队列专题】—— 滑动窗口
UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
缓存淘汰算法初步认识(LRU和LFU)
Leetcode 709, convert to lowercase
bounding box iou
PostgreSQL basic functions
LeetCode 1337、矩阵中战斗力最弱的 K 行
Thirty What are VM and VC?
High paid programmer & interview question series 91 limit 20000 loading is very slow. How to solve it? How to locate slow SQL?
2021-06-29 C escape character cancellation and use