SQLite 的 DELETE 查詢(xún)用于刪除表中已有的記錄??梢允褂脦в?WHERE 子句的 DELETE 查詢(xún)來(lái)刪除選定行,否則所有的記錄都會(huì)被刪除。
帶有 WHERE 子句的 DELETE 查詢(xún)的基本語(yǔ)法如下:
DELETE FROM table_name
WHERE [condition];
您可以使用 AND 或 OR 運(yùn)算符來(lái)結(jié)合 N 個(gè)數(shù)量的條件。
假設(shè) COMPANY 表有以下記錄:
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
下面是一個(gè)實(shí)例,它會(huì)刪除 ID 為 7 的客戶(hù):
sqlite> DELETE FROM COMPANY WHERE ID = 7;
現(xiàn)在,COMPANY 表有以下記錄:
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
如果您想要從 COMPANY 表中刪除所有記錄,則不需要使用 WHERE 子句,DELETE 查詢(xún)?nèi)缦拢?/p>
sqlite> DELETE FROM COMPANY;
現(xiàn)在,COMPANY 表中沒(méi)有任何的記錄,因?yàn)樗械挠涗浺呀?jīng)通過(guò) DELETE 語(yǔ)句刪除。