SQLite Delete 语句


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

 

1. 语法

带有 where 子句的 delete 查询的基本语法如下:

delete from table_name
where [condition];

您可以使用 and 或 or 运算符来结合 n 个数量的条件。

 

2. 范例

假设 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 语句删除。

下一节:sqlite like 子句

sqlite教程

相关文章