How can you check a SQLite database's structural consistency?

integrity_check examines tables, indexes and a range of internal consistency conditions. A clean full check returns ok.

SQLite example and interpretation

The fixture checks a small experiment table. A clean structural result cannot tell you whether labels are correct, and foreign keys have their own check.

CREATE TABLE r(id INTEGER PRIMARY KEY,v TEXT);
INSERT INTO r VALUES(1,'a'),(2,'b');
PRAGMA integrity_check;

Result [["ok"]]

中文

如何检查 SQLite 文件的内部结构是否自洽?

integrity_check 检查表、索引及多项内部一致性条件。完整检查没有发现问题时返回 ok。

SQLite 示例与适用条件

示例建立两条实验记录后执行结构检查。结果无法说明标签是否贴对,外键完整性也应使用专门检查。

CREATE TABLE r(id INTEGER PRIMARY KEY,v TEXT);
INSERT INTO r VALUES(1,'a'),(2,'b');
PRAGMA integrity_check;

结果 [["ok"]]

References / 参考来源

Keep reading / 继续阅读