MySQL Delete From指令怎么使用
MySQL的DELETE FROM指令用于从表中删除记录。- condition:可选参数,用于指定删除记录的条件。例如,我们有一个名为"customers"的表,其中包含以下数据:```+----+----------+-----+-----------+| id | name | age | city |+----+----------+-----+-----------+| 1 | John | 25 | New York || 2 | Mary | 30 | London || 3 | Bob | 35 | Paris |+----+----------+-----+-----------+```要删除名字为"John"的记录,可以使用以下DELETE FROM语句:```DELETE FROM customersWHERE name = 'John';```执行此语句后,"customers"表将变为:```+----+----------+-----+-----------+| id | name | age | city |+----+----------+-----+-----------+| 2 | Mary | 30 | London || 3 | Bob | 35 | Paris |+----+----------+-----+-----------+```如果要删除活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!!
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 |
+----+----------+-----+-----------+
```
如果要删除活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看所有记录,可以省略WHERE条件:
```
DELETE FROM customers;
```
这将删除表中的所有记录,使表变为空。