Data Types
Understand SQLite storage classes, type affinity, NULL, booleans, dates, and typeof results.
Every value in SQLite has a storage class: the kind of value SQLite is actually storing. Every column can also have a declared type, which gives the column a type affinity.
That sounds technical, but the beginner idea is simple:
In SQLite, the value itself has the strongest type. The column's declared type is a helpful preference, not always a strict wall.
SQLite is flexible about types
Some database systems are rigid: if a column is declared as a number, text that is not a number is rejected.
SQLite is different. SQLite uses dynamic typing. A column declaration gives SQLite a preference, called affinity, but SQLite may still store a value of another kind.
This flexibility is convenient, but it also means you should be thoughtful. If a column is meant to hold ages, you should still insert ages, not random words.
Affinity is not the same as strict validation
A declared type in a regular SQLite table is a strong hint about how values should be stored. It is not the same as a strict rule that rejects every mismatched value.
The five storage classes
SQLite stores values using five storage classes:
| Storage class | Holds | Examples |
|---|---|---|
NULL | Missing or unknown value | NULL |
INTEGER | Whole numbers | 0, 42, -7 |
REAL | Floating-point numbers | 3.14, 19.99 |
TEXT | Text strings | 'Ada', '2026-03-14' |
BLOB | Raw bytes | Images or binary data |
Most beginner tables use INTEGER, TEXT, REAL, and sometimes NUMERIC as declared column types. NULL is a value state, not a declared column type you usually choose.
Declared types become affinities
When you write a column type, SQLite maps it to an affinity. Affinity is the column's preferred storage behavior.
Here is a beginner-friendly summary:
| Declared type you might write | Affinity | Common use |
|---|---|---|
INTEGER | INTEGER | ids, counts, whole numbers |
TEXT | TEXT | names, emails, labels, dates as text |
REAL | REAL | measurements and approximate decimals |
NUMERIC | NUMERIC | numbers that may be integer or decimal, including 0/1 flags |
BLOB | BLOB | raw binary data |
SQLite's full mapping rules look at words inside the declared type. For beginners, use clear names like INTEGER, TEXT, REAL, and NUMERIC.
typeof() shows the storage class
SQLite has a helpful function named typeof() that reports how a value is actually stored.
A NUMERIC affinity column tries to store numeric-looking text as numbers. So '42' may become an integer, and '3.14' may become real. But 'banana' cannot sensibly become a number, so SQLite stores it as text.
In a regular SQLite table, what does a column's declared type mainly provide?
A paint color for the column.
A type affinity, which is SQLite's preferred way to store values in that column.
A guarantee that no other storage class can ever appear.
A rule that every value becomes NULL.
SQLite compared with rigid type systems
Think of a rigid system as a locked door and SQLite affinity as a helpful sign.
This does not mean types do not matter in SQLite. They still matter because they help:
- document what the column is for,
- make numeric-looking values behave like numbers,
- make your table easier for people to understand,
- support predictable queries when you store consistent values.
NULL means missing or unknown
NULL means the value is missing, unknown, or not applicable. It is not the same as zero, an empty string, or the word 'NULL'.
For example, if you do not know a customer's phone number yet, NULL is better than making up a fake value.
Booleans in SQLite
SQLite does not have a separate boolean storage class. Store true/false values as integers:
1for true0for false
Example column:
is_active INTEGERThen query it like this:
SELECT name
FROM users
WHERE is_active = 1;Dates and times in SQLite
SQLite does not have a separate date or timestamp storage class. Common choices are:
For beginners, storing dates as TEXT in ISO format is easiest:
created_on TEXTExample values:
'2026-03-14''2026-03-14 09:30:00'
The YYYY-MM-DD format sorts naturally as text when every date uses the same format.
See flexible typing in action
This example stores values in columns with different affinities and uses typeof() to show what SQLite actually stored.
Look closely at the output. SQLite converts some values based on affinity, but not every value. That is the key idea.
Choosing types as a beginner
Use this simple guide:
| Need to store | Beginner SQLite choice |
|---|---|
| id or count | INTEGER |
| name, email, category, date text | TEXT |
| measurement with decimals | REAL |
| money-like amount in simple examples | NUMERIC |
| true or false | INTEGER with 0 or 1 |
| unknown value | NULL value in the cell |
Consistency is your responsibility
SQLite's flexibility is friendly, but it will not always stop messy data. If a column is meant for prices, store prices consistently.
Check your understanding
Which list contains SQLite's five storage classes?
INTEGER, TEXT, REAL, NUMERIC, BOOLEAN.
NULL, INTEGER, REAL, TEXT, BLOB.
SERIAL, DATE, MONEY, TEXT, JSON.
ROW, COLUMN, TABLE, CELL, SCHEMA.
What does typeof(value) report in SQLite?
The name of the table that contains the value.
The storage class of the value SQLite is actually holding.
The number of rows in the table.
Whether the column is a primary key.
How should beginners usually store true/false values in SQLite?
As a separate BOOLEAN storage class.
As INTEGER values, commonly 1 for true and 0 for false.
As table names.
As random words like maybe and sometimes.
Which date storage choice is simplest for beginners in SQLite?
Store dates as many different text formats, such as March 14 and 14/03/26.
Store dates as TEXT using a consistent format like '2026-03-14'.
Store dates as a primary key in every table.
Store dates only as column names.
A NUMERIC affinity column receives the text value '42'. What is SQLite likely to do?
Delete the table immediately.
Convert and store it as a numeric value, commonly an integer.
Always store it as a BLOB.
Refuse every quoted value no matter what it contains.