SQLite 教程
1. SQLite 教程 2. SQLite 简介 3. SQLite 安装 4. SQLite 命令 5. SQLite 语法 6. SQLite 数据类型 7. SQLite 创建数据库 8. SQLite 附加数据库 9. SQLite 分离数据库 10. SQLite 创建表 11. SQLite 删除表 12. SQLite Insert 语句 13. SQLite Select 语句 14. SQLite 运算符 15. SQLite 表达式 16. SQLite Where 子句 17. SQLite AND/OR 运算符 18. SQLite Update 语句 19. SQLite Delete 语句 20. SQLite Like 子句 21. SQLite Glob 子句 22. SQLite Limit 子句 23. SQLite Order By 24. SQLite Group By 25. SQLite Having 子句 26. SQLite Distinct 关键字 27. SQLite PRAGMA 28. SQLite 约束 29. SQLite Join 30. SQLite Unions 子句 31. SQLite NULL 值 32. SQLite 别名 33. SQLite 触发器 34. SQLite 索引 35. SQLite Indexed By 36. SQLite Alter 命令 37. SQLite Truncate Table 38. SQLite 视图 39. SQLite 事务 40. SQLite 子查询 41. SQLite Autoincrement 42. SQLite 注入 43. SQLite Explain 44. SQLite Vacuum 45. SQLite 日期 & 时间 46. SQLite 常用函数 47. SQLite – C/C++ 48. SQLite – Java 49. SQLite – PHP 50. SQLite – Perl 51. SQLite – Python

SQLite Delete 语句

SQLite Delete 语句

SQLite 的 DELETE 查询用于删除表中已有的记录。可以使用带有 WHERE 子句的 DELETE 查询来删除选定行,否则所有的记录都会被删除。

语法

带有 WHERE 子句的 DELETE 查询的基本语法如下:


DELETE FROM table_name

WHERE [condition];

您可以使用 AND 或 OR 运算符来结合 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

7           James       24          Houston     10000.0

下面是一个实例,它会删除 ID 为 7 的客户:


sqlite> DELETE FROM COMPANY WHERE ID = 7;

现在,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 查询如下:


sqlite> DELETE FROM COMPANY;

现在,COMPANY 表中没有任何的记录,因为所有的记录已经通过 DELETE 语句删除。