Daniel Lyons' Notes

strict tables in SQLite

At least some features of dynamic typing can be opted out of, by using the STRICT when declaring the table.

Docs and Reference

Creating a STRICT Table

CREATE TABLE strict_table_name(
    column type constraint, 
    ...
) STRICT;

The strict tables follow these rules:

  • Every column must have one of the following data types: INTINTEGERREALTEXTBLOB, and ANY.
  • When inserting a value into a column, SQLite will attempt to convert the value into the column’s data type. If the conversion fails, it will raise an error.
  • Columns with the ANY data type can accept any kind of data. SQLite will not perform any conversion for these columns.
  • PRIMARY KEY columns are implicitly [NOT NULL](https://www.sqlitetutorial.net/sqlite-not-null-constraint/).
  • The PRAGMA integrity_check and PRAGMA quick_check commands verify the type of the contents of all columns in strict tables and display errors if any mismatches are found.
strict tables in SQLite
Interactive graph
On this page
Docs and Reference
Creating a STRICT Table