鍍金池/ 教程/ 數(shù)據(jù)庫(kù)/ MariaDB刪除數(shù)據(jù)
MariaDB比較運(yùn)算符
MariaDB查詢數(shù)據(jù)
MariaDB Like子句
MariaDB Sum()函數(shù)
MariaDB過(guò)程
MariaDB限制返回記錄
MariaDB Count()函數(shù)
MariaDB更新數(shù)據(jù)
MariaDB導(dǎo)出數(shù)據(jù)
MariaDB Intersect運(yùn)算符
MariaDB函數(shù)
MariaDB Min()函數(shù)
MariaDB創(chuàng)建數(shù)據(jù)庫(kù)
MariaDB Avg()函數(shù)
MariaDB刪除數(shù)據(jù)
MariaDB條件
MariaDB功能特點(diǎn)
MariaDB創(chuàng)建表
MariaDB左外連接
MariaDB Union運(yùn)算符
MariaDB安裝
MariaDB選擇數(shù)據(jù)庫(kù)
MariaDB Max()函數(shù)
MariaDB Where子句
MariaDB右外連接
MariaDB內(nèi)連接
MariaDB截?cái)啾?/span>
MariaDB Order By子句
MariaDB教程
MariaDB正則表達(dá)式
MariaDB Union All運(yùn)算符
MariaDB Distinct子句
MariaDB修改表
MariaDB刪除表
MariaDB插入數(shù)據(jù)
MariaDB From子句
MariaDB刪除數(shù)據(jù)庫(kù)
MariaDB簡(jiǎn)介
MariaDB數(shù)據(jù)類型

MariaDB刪除數(shù)據(jù)

MariaDB DELETE語(yǔ)句用于從MariaDB數(shù)據(jù)庫(kù)的表中刪除一個(gè)或多個(gè)記錄。

語(yǔ)法:

DELETE FROM table  
[WHERE conditions]  
[ORDER BY expression [ ASC | DESC ]]  
[LIMIT number_rows];

1. 使用條件刪除數(shù)據(jù)

下面演示如何使用指定的一個(gè)條件來(lái)刪除數(shù)據(jù)。

示例:

DELETE FROM Students  
WHERE student_name = 'Blaba';

在執(zhí)行上面刪除語(yǔ)句后,現(xiàn)在查詢表中的數(shù)據(jù) -

2. 使用多個(gè)條件刪除數(shù)據(jù)

假設(shè)數(shù)據(jù)庫(kù)表students中的student_name有兩個(gè)Maxsu值,現(xiàn)在想刪除student_id不是1的所有Maxsu值,參考以下語(yǔ)句 -

首先插入兩條件記錄 -

INSERT INTO Students  
(student_name, student_address, admission_date) 
VALUES('Maxsu','Sanya','2016-03-09 00:00:00');
-- 再插入另一條記錄
INSERT INTO Students  
(student_name, student_address, admission_date) 
VALUES('Ajeet','Sanya','2015-12-07 00:00:00');

查詢當(dāng)數(shù)據(jù)庫(kù)中的記錄 -

MariaDB [testdb]> select * from students;
+------------+--------------+-----------------+----------------+
| student_id | student_name | student_address | admission_date |
+------------+--------------+-----------------+----------------+
|          1 | Maxsu        | Haikou          | 2017-01-07     |
|          3 | JMaster      | Beijing         | 2016-05-07     |
|          4 | Mahesh       | Guangzhou       | 2016-06-07     |
|          5 | 科比         | Haikou          | 2016-02-07     |
|          7 | Maxsu        | Sanya           | 2016-03-09     |
|          8 | Ajeet        | Sanya           | 2015-12-07     |
+------------+--------------+-----------------+----------------+
6 rows in set (0.00 sec)

刪除那些student_id大于1,并且student_nameMaxsu的記錄 -

DELETE FROM Students
WHERE student_name = 'Maxsu'
AND student_id > 1;

執(zhí)行上面刪除語(yǔ)句以后,現(xiàn)在查詢表中的記錄 -

MariaDB [testdb]> select * from students;
+------------+--------------+-----------------+----------------+
| student_id | student_name | student_address | admission_date |
+------------+--------------+-----------------+----------------+
|          1 | Maxsu        | Haikou          | 2017-01-07     |
|          3 | JMaster      | Beijing         | 2016-05-07     |
|          4 | Mahesh       | Guangzhou       | 2016-06-07     |
|          5 | 科比         | Haikou          | 2016-02-07     |
|          8 | Ajeet        | Sanya           | 2015-12-07     |
+------------+--------------+-----------------+----------------+
5 rows in set (0.00 sec)

可以看到,student_id7,并且student_name值為Maxsu的記錄被刪除了。