全部教程·
数据库·
Sqlite
[目录]
·
SQLite Vacuum
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 Vacuum
VACUUM 命令通过复制主数据库中的内容到一个临时数据库文件,然后清空主数据库,并从副本中重新载入原始的数据库文件。这消除了空闲页,把表中的数据排列为连续的,另外会清理数据库文件结构。
如果表中没有明确的整型主键(INTEGER PRIMARY KEY),VACUUM 命令可能会改变表中条目的行 ID(ROWID)。VACUUM 命令只适用于主数据库,附加的数据库文件是不可能使用 VACUUM 命令。
如果有一个活动的事务,VACUUM 命令就会失败。VACUUM 命令是一个用于内存数据库的任何操作。由于 VACUUM 命令从头开始重新创建数据库文件,所以 VACUUM 也可以用于修改许多数据库特定的配置参数。
1. 手动 VACUUM
下面是在命令提示符中对整个数据库发出 VACUUM 命令的语法:
$sqlite3 database_name "VACUUM;"
您也可以在 SQLite 提示符中运行 VACUUM,如下所示:
sqlite> VACUUM;
您也可以在特定的表上运行 VACUUM,如下所示:
sqlite> VACUUM table_name;
2. 自动 VACUUM(Auto-VACUUM)
SQLite 的 Auto-VACUUM 与 VACUUM 不大一样,它只是把空闲页移到数据库末尾,从而减小数据库大小。通过这样做,它可以明显地把数据库碎片化,而 VACUUM 则是反碎片化。所以 Auto-VACUUM 只会让数据库更小。
在 SQLite 提示符中,您可以通过下面的编译运行,启用/禁用 SQLite 的 Auto-VACUUM:
sqlite> PRAGMA auto_vacuum = NONE; -- 0 means disable auto vacuum sqlite> PRAGMA auto_vacuum = INCREMENTAL; -- 1 means enable incremental vacuum sqlite> PRAGMA auto_vacuum = FULL; -- 2 means enable full auto vacuum
您可以从命令提示符中运行下面的命令来检查 auto-vacuum 设置:
$sqlite3 database_name "PRAGMA auto_vacuum;"
下一章:SQLite 日期 & 时间
SQLite 支持以下五个日期和时间函数:序号函数范例1date(timestring, modifier, modifier, ...)以 YYYY-MM-DD 格式返回日期。2time(timestring ...
AI 中文社