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;
這將刪除表中的所有記錄,使表變為空。