SQLite STRICT Tables
What is a STRICT Table?
Normally, SQLite lets you store any type of value in any column. In a STRICT table, SQLite checks the data type of every value, and gives an error if a value has the wrong type.
Add the keyword STRICT after the closing parenthesis:
Example
CREATE TABLE IF NOT EXISTS Items (
ItemID INTEGER PRIMARY KEY,
Name TEXT,
Price REAL
) STRICT;
Try it Yourself »
Note: STRICT tables work in SQLite 3.37.0 and later.
Wrong Type Gives an Error
The text 'cheap' cannot be stored in the REAL column Price:
Example
CREATE TABLE IF NOT EXISTS Items (
ItemID INTEGER PRIMARY KEY,
Name TEXT,
Price REAL
) STRICT;
INSERT INTO Items (Name, Price)
VALUES ('Pen', 'cheap');
Try it Yourself »
Text that looks like a number, like '9.5', is still turned into a number and stored.
Allowed Types
In a STRICT table, each column must have one of these types:
| Type | Holds |
|---|---|
INT or INTEGER | Whole numbers |
REAL | Decimal numbers |
TEXT | Text |
BLOB | Binary data |
ANY | Any type of value, exactly as it was given |
Other type names, like VARCHAR(255) or DATE, give an error in a STRICT table.