当前位置:网站首页>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
边栏推荐
- 內網滲透之DOS命令
- Experience of mathematical modeling in 18 year research competition
- 2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
- LeetCode 994、腐烂的橘子
- 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
- Solution to PowerDesigner's failure to connect to MySQL in x64 system
- Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
- How to do after winning the new debt? Is it safe to open an account online
- Install MySQL 5.0 under Linux 64bit 6 - the root password cannot be modified
- Bash script learning -- for loop traversal
猜你喜欢

2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real

Leetcode 994, rotten orange

【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行

Devexpress 14.1 installation record

Rt-1052 learning notes - GPIO architecture analysis

Unity solves Z-fighting

Summary and effect analysis of methods for calculating binocular parallax

go slice

Installation and use of NVM

"Meta function" of tidb 6.0: what is placement rules in SQL?
随机推荐
【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
How to configure SSH public key in code cloud
LeetCode 116. Populate the next right node pointer for each node
LeetCode 116. 填充每个节点的下一个右侧节点指针
Go zero framework database avoidance Guide
A useless confession artifact
The ODB model calculates the data and outputs it to excel
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
Recognition of high-speed road signs by Matlab using alexnet
I JS deep copy and shallow copy
High paid programmer & interview question series 91 limit 20000 loading is very slow. How to solve it? How to locate slow SQL?
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
How do BIM swindlers cheat? (turn)
How many hacking methods do you know?
JS arrow function user and processing method of converting arrow function into ordinary function
Easy to use nprogress progress bar
Learn to C language fourth day
打新债中签以后怎么办,网上开户安全吗
Installation and use of NVM
【PTA】L2-011 玩转二叉树