MySQL从小白到总裁完整教程目录:https://blog.csdn.net/weixin_67859959/article/details/129334507?spm=1001.2014.3001.5502
语法格式:
delete from 表名 where 记录匹配条件;
说明:如果**不写where**子句,表示无条件,删除表中的**所有记录**(行)!
delete 删除
from 来自、对于
案列:删除test03表中,姓名(name)是rose的记录
mysql> delete from test03 where name='rose';
Query OK, 1 row affected (0.05 sec)mysql> select * from test03;
+------+------+--------+------------+---------+
| name | age | salary | etime | address |
+------+------+--------+------------+---------+
| king | 20 | 999.00 | 2022-01-01 | NULL |
| tom | 23 | 999.00 | 2022-01-01 | 广州 |
| Mary | 19 | 777.00 | 2022-01-01 | NULL |
| lucy | 21 | 88.00 | 2022-01-01 | 上海 |
+------+------+--------+------------+---------+
4 rows in set (0.00 sec)
Query OK, 1 row affected (0.00 sec)
1 行 被影响了!
练习:删除test01中,编号(id)是102的记录
mysql> select * from test01;
+------+------+------+
| id | name | age |
+------+------+------+
| 101 | rose | 20 |
| 102 | Jack | 25 |
+------+------+------+
2 rows in set (0.00 sec)mysql> delete from test01 where id=102;
Query OK, 1 row affected (0.00 sec)mysql> select * from test01;
+------+------+------+
| id | name | age |
+------+------+------+
| 101 | rose | 20 |
+------+------+------+
1 row in set (0.00 sec)
练习:删除test03表中的所有记录
mysql> delete from test03;
Query OK, 4 rows affected (0.02 sec)mysql> select * from test03;
Empty set (0.00 sec)
提示:Query OK, 4 rows affected (0.00 sec)
4 行 被影响了
提示:Empty set (0.00 sec) 空的集合,就是没有数据