mysql

MySQL Delete From指令怎么使用

小亿
126
2023-10-12 14:43:18
栏目: 云计算

MySQL的DELETE FROM指令用于从表中删除记录。其语法如下:

DELETE FROM table_name
WHERE condition;

例如,我们有一个名为"customers"的表,其中包含以下数据:

+----+----------+-----+-----------+
| id | name     | age | city      |
+----+----------+-----+-----------+
| 1  | John     | 25  | New York  |
| 2  | Mary     | 30  | London    |
| 3  | Bob      | 35  | Paris     |
+----+----------+-----+-----------+

要删除名字为"John"的记录,可以使用以下DELETE FROM语句:

DELETE FROM customers
WHERE name = 'John';

执行此语句后,"customers"表将变为:

+----+----------+-----+-----------+
| id | name     | age | city      |
+----+----------+-----+-----------+
| 2  | Mary     | 30  | London    |
| 3  | Bob      | 35  | Paris     |
+----+----------+-----+-----------+

如果要删除所有记录,可以省略WHERE条件:

DELETE FROM customers;

这将删除表中的所有记录,使表变为空。

0
看了该问题的人还看了