MySQL的DELETE FROM指令用于从表中删除记录。其语法如下:
DELETE FROM table_name
WHERE condition;
table_name:要删除记录的表名。
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;
这将删除表中的所有记录,使表变为空。