delete from table_name [where ];
table_name表示要執行刪除操作的表;[where ]為可選引數,用於指定刪除條件,如果沒有where子句,delete語句將刪除表中所有記錄。
例:刪除person表中,id=11的記錄:
刪除前:
mysql> select * from person;
+----+---------+-----+-----------+
| id | name | age | info |
+----+---------+-----+-----------+
| 1 | green | 21 | student |
| 2 | suse | 22 | student |
| 3 | mary | 24 | musician |
| 4 | willam | 20 | student |
| 5 | laura | 25 | null |
| 6 | evans | 27 | secretary |
| 7 | dale | 22 | student |
| 8 | edison | 28 | singer |
| 11 | liming | 15 | student |
| 12 | beckham | 31 | police |
+----+---------+-----+-----------+
10 rows in set (0.00 sec)
刪除:
mysql> delete from person where id=11;
query ok, 1 row affected (0.19 sec)
刪除後:
mysql> select * from person;
+----+---------+-----+-----------+
| id | name | age | info |
+----+---------+-----+-----------+
| 1 | green | 21 | student |
| 2 | suse | 22 | student |
| 3 | mary | 24 | musician |
| 4 | willam | 20 | student |
| 5 | laura | 25 | null |
| 6 | evans | 27 | secretary |
| 7 | dale | 22 | student |
| 8 | edison | 28 | singer |
| 12 | beckham | 31 | police |
+----+---------+-----+-----------+
9 rows in set (0.00 sec)
例:
在person表中使用delete語句同時刪除多條記錄:
mysql> select * from person where age between 19 and 22;
+----+--------+-----+---------+
| id | name | age | info |
+----+--------+-----+---------+
| 1 | green | 21 | student |
| 2 | suse | 22 | student |
| 4 | willam | 20 | student |
| 7 | dale | 22 | student |
+----+--------+-----+---------+
4 rows in set (0.00 sec)
刪除:
mysql> delete from person where age between 19 and 22;
query ok, 4 rows affected (0.07 sec)
刪除後:
mysql> select * from person where age between 19 and 22;
empty set (0.00 sec)
例:刪除person表中所有記錄:
刪除前:
mysql> select * from person;
+----+---------+-----+-----------+
| id | name | age | info |
+----+---------+-----+-----------+
| 3 | mary | 24 | musician |
| 5 | laura | 25 | null |
| 6 | evans | 27 | secretary |
| 8 | edison | 28 | singer |
| 12 | beckham | 31 | police |
+----+---------+-----+-----------+
5 rows in set (0.00 sec)
刪除:
mysql> delete from person;
query ok, 5 rows affected (0.02 sec)
刪除後:
mysql> select * from person;
empty set (0.00 sec)
TP5使用模型刪除資料
1.靜態方法 destroy,返回受影響的行數,下面的情況是 引數為主鍵的情況 res user destroy 1 dump res 引數也可以是乙個陣列 res user destroy id 2 dump res 引數也可以是乙個閉包函式 res user destroy function q...
vector刪除資料
6.以下 有什麼問題?stl易 typedef vector intarray intarray array array.push back 1 array.push back 2 array.push back 2 array.push back 3 刪除array陣列中所有的2 for inta...
刪除資料記錄
根據多個標識列刪除資料記錄 一 首先id列是int標識類型別,然後刪除id值為5,6,8,9,10,11的列,這裡的cast函式不能用convert函式代替,而且轉換的型別必須是varchar,而不能是char,否則就會執行出你不希望的結果,這裡的 5,6,8,9,10,11 可以是你在頁面上獲取的...