欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
全部教程·
数据库·
Sqlite
[目录]
·
SQLite Truncate Table
SQLite教程
SQLite 安装
SQLite 命令
SQLite 语法
SQLite 数据类型
SQLite 创建数据库
SQLite 附加数据库
SQLite 分离数据库
SQLite 创建表
SQLite 删除表
SQLite Insert 语句
SQLite Select 语句
SQLite 运算符
SQLite 表达式
SQLite Where 子句
SQLite AND/OR 运算符
SQLite Update 语句
SQLite Delete 语句
SQLite Like 子句
SQLite Glob 子句
SQLite Limit 子句
SQLite Order By
SQLite Group By
SQLite Having 子句
SQLite Distinct 关键字
SQLite PRAGMA
SQLite 约束
SQLite Join
SQLite Unions 子句
SQLite NULL 值
SQLite 别名
SQLite 触发器
SQLite Indexed By
SQLite Alter 命令
SQLite Truncate Table
SQLite 视图
SQLite 事务
SQLite 子查询
SQLite Autoincrement
SQLite 注入
SQLite Explain
SQLite Vacuum
SQLite 日期 & 时间
SQLite 常用函数
SQLite C/C++ 接口
SQLite Java 接口
SQLite PHP 接口
SQLite Perl 接口
SQLite Python 接口
SQLite教程
SQLite 安装
SQLite 命令
SQLite 语法
SQLite 数据类型
SQLite 创建数据库
SQLite 附加数据库
SQLite 分离数据库
SQLite 创建表
SQLite 删除表
SQLite Insert 语句
SQLite Select 语句
SQLite 运算符
SQLite 表达式
SQLite Where 子句
SQLite AND/OR 运算符
SQLite Update 语句
SQLite Delete 语句
SQLite Like 子句
SQLite Glob 子句
SQLite Limit 子句
SQLite Order By
SQLite Group By
SQLite Having 子句
SQLite Distinct 关键字
SQLite PRAGMA
SQLite 约束
SQLite Join
SQLite Unions 子句
SQLite NULL 值
SQLite 别名
SQLite 触发器
SQLite Indexed By
SQLite Alter 命令
SQLite Truncate Table
SQLite 视图
SQLite 事务
SQLite 子查询
SQLite Autoincrement
SQLite 注入
SQLite Explain
SQLite Vacuum
SQLite 日期 & 时间
SQLite 常用函数
SQLite C/C++ 接口
SQLite Java 接口
SQLite PHP 接口
SQLite Perl 接口
SQLite Python 接口
SQLite Truncate Table
在 SQLite 中,并没有 TRUNCATE TABLE 命令,但可以使用 SQLite 的 DELETE 命令从已有的表中删除全部的数据。
1. 语法
DELETE 命令的基本语法如下:
sqlite> DELETE FROM table_name;
但这种方法无法将递增数归零。
如果要将递增数归零,可以使用以下方法:
sqlite> DELETE FROM sqlite_sequence WHERE name = 'table_name';
当 SQLite 数据库中包含自增列时,会自动建立一个名为 sqlite_sequence 的表。这个表包含两个列:name 和 seq。name 记录自增列所在的表,seq 记录当前序号(下一条记录的编号就是当前序号加 1)。如果想把某个自增列的序号归零,只需要修改 sqlite_sequence 表就可以了。
UPDATE sqlite_sequence SET seq = 0 WHERE name = 'table_name';
假设 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
下面为删除上表记录的范例:
SQLite> DELETE FROM sqlite_sequence WHERE name = 'COMPANY'; SQLite> VACUUM;
现在,COMPANY 表中的记录完全被删除,使用 SELECT 语句将没有任何输出。
下一章:SQLite 视图
视图(View)只不过是通过相关的名称存储在数据库中的一个 SQLite 语句。视图(View)实际上是一个以预定义的 SQLite 查询形式存在的表的组合。视图(View)可以包含一个表的所有行或从一个或多个表选定行。 ...
AI 中文社