鍍金池/ 教程/ 數(shù)據(jù)庫(kù)/ SQLite Delete 語(yǔ)句
SQLite Having 子句
SQLite 運(yùn)算符
SQLite 注入
SQLite Delete 語(yǔ)句
SQLite – Python
SQLite 數(shù)據(jù)類(lèi)型
SQLite 簡(jiǎn)介
SQLite 創(chuàng)建數(shù)據(jù)庫(kù)
SQLite Vacuum
SQLite Group By
SQLite 日期 & 時(shí)間
SQLite AND/OR 運(yùn)算符
SQLite 刪除表
SQLite Distinct
SQLite Alter 命令
SQLite PRAGMA
SQLite 約束
SQLite 創(chuàng)建表
SQLite Like 子句
SQLite Limit 子句
SQLite Autoincrement
SQLite 子查詢(xún)
SQLite – C/C++
SQLite – PHP
SQLite 命令
SQLite Order By
SQLite Select 語(yǔ)句
SQLite Unions 子句
SQLite – Perl
SQLite – Java
SQLite 別名
SQLite 常用函數(shù)
SQLite Explain(解釋?zhuān)?/span>
SQLite NULL 值
SQLite Glob 子句
SQLite 表達(dá)式
SQLite 視圖
SQLite Where 子句
SQLite Truncate Table
SQLite 索引
SQLite Insert 語(yǔ)句
SQLite 安裝
SQLite Indexed By
SQLite 分離數(shù)據(jù)庫(kù)
SQLite 觸發(fā)器
SQLite 語(yǔ)法
SQLite Joins
SQLite Update 語(yǔ)句
SQLite 附加數(shù)據(jù)庫(kù)
SQLite 事務(wù)

SQLite Delete 語(yǔ)句

SQLite 的 DELETE 查詢(xún)用于刪除表中已有的記錄??梢允褂脦в?WHERE 子句的 DELETE 查詢(xún)來(lái)刪除選定行,否則所有的記錄都會(huì)被刪除。

語(yǔ)法

帶有 WHERE 子句的 DELETE 查詢(xún)的基本語(yǔ)法如下:

    DELETE FROM table_name
    WHERE [condition];

您可以使用 AND 或 OR 運(yùn)算符來(lái)結(jié)合 N 個(gè)數(shù)量的條件。

實(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ǔ)句刪除。