SQLite PRAGMA

PRAGMA integrity_check

This pragma does a low-level formatting and consistency check of the database.

PRAGMA schema.integrity_check;
PRAGMA schema.integrity_check(N) PRAGMA schema.integrity_check(TABLENAME)

On the sample database

What PRAGMA integrity_check returns on the sample database, in SQLite 3.54.1 as built for the browser by sql.js:

integrity_check
ok

What the SQLite documentation says

This pragma does a low-level formatting and consistency check of the database. The integrity_check pragma look for:

If the integrity_check pragma finds problems, strings are returned (as multiple rows with a single column per row) which describe the problems. Pragma integrity_check will return at most N errors before the analysis quits, with N defaulting to 100. If pragma integrity_check finds no errors, a single row with the value 'ok' is returned.

The usual case is that the entire database file is checked. However, if the argument is TABLENAME, then checking is only performed for the the table named and its associated indexes. This is called a "partial integrity check". Because only a subset of the database is checked, errors such as unused sections of the file or duplication use of the same section of the file by two or more tables cannot be detected. The freelist is only verified on a partial integrity check if TABLENAME is sqlite_schema or one of its aliases. Support for partial integrity checks was added with version 3.33.0 (2020-08-14).

PRAGMA integrity_check does not find FOREIGN KEY errors. Use the PRAGMA foreign_key_check command to find errors in FOREIGN KEY constraints.

See also the PRAGMA quick_check command which does most of the checking of PRAGMA integrity_check but runs much faster.

From sqlite.org's pragma documentation for SQLite 3.54.1, in the public domain.

← index_xinfo · journal_mode →