sqlite - 在 "DELETE FROM table"之后更改 sqlite 文件大小

标签 sqlite

我正在使用 sqlite3 文件。

首先,我进入了比较大的数据库,文件大小大约是100mb。

比我做的

$db->exec("DELETE FROM table");

并只输入了该数据库的一小部分。但文件大小仍为 100 MB。

删除内容时应该如何更改 sqlite 文件大小?

最佳答案

您要查找的命令是vacuum .还有一个pragma打开自动清理。

来自文档:

When an object (table, index, trigger, or view) is dropped from the database, it leaves behind empty space. This empty space will be reused the next time new information is added to the database. But in the meantime, the database file might be larger than strictly necessary. Also, frequent inserts, updates, and deletes can cause the information in the database to become fragmented - scrattered out all across the database file rather than clustered together in one place.

The VACUUM command cleans the main database by copying its contents to a temporary database file and reloading the original database file from the copy. This eliminates free pages, aligns table data to be contiguous, and otherwise cleans up the database file structure.

关于sqlite - 在 "DELETE FROM table"之后更改 sqlite 文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2143800/

相关文章:

sqlite - 我应该制作多个 SQLite 数据库以获得更好的并发性吗?

java - Eclipse 项目上的多个 JDBC 文件

objective-c - 使用 FMDB 从 sqlite DB 创建字典数组

Python - 从 SQLite3 数据库中读取 BLOB 类型

将输出格式设置为 "table"(.mode 表)时出现 SQLite3 错误

java - 来回更改 ListView 适配器?

python-3.x - 在函数中打开另一个 .py 文件以在 Python3.5 中传递参数

android - 如何从网络加载数据到android

sqlite3 准备、绑定(bind)和重置语句

ANDROID SQLITE 检查表是否有数据