SQLite PRAGMA Statements
What is PRAGMA?
A PRAGMA statement reads or changes a setting of SQLite, or gives information about the database. It is special for SQLite.
PRAGMA pragma_name;
PRAGMA pragma_name = value;
Information About a Table
PRAGMA table_info lists the columns of a table, with their types:
Many pragmas can also be used as a table in a SELECT, with the name pragma_ in front:
Foreign Keys
PRAGMA foreign_keys turns the foreign key check on or off. It is off by default:
Check the Database
PRAGMA integrity_check checks the database file for errors. It returns "ok" if everything is fine:
Useful Pragmas
| Pragma | Description |
|---|---|
table_info(table) | Lists the columns of a table |
index_list(table) | Lists the indexes of a table |
foreign_keys | Turns the foreign key check on or off |
journal_mode | Sets how changes are written. WAL is good when many programs read the database at the same time |
integrity_check | Checks the database for errors |
user_version | A number you can use for the version of your own database design |
database_list | Lists the attached databases |