English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SQLite data types are a property used to specify the data type of any object. Each column, variable, and expression in SQLite has a corresponding data type.
You will use these data types when creating tables. SQLite uses a more general dynamic type system. In SQLite, the data type of a value is associated with the value itself, not with its container.
Each value stored in the SQLite database has one of the following storage classes-
Serial number | Storage class and description |
---|---|
1 |
This value is a NULL value. |
2 |
This value is a signed integer, stored in1,2,3,4,6or8bytes. |
3 |
This value is a floating-point value, stored as8byte IEEE floating-point number. |
4 |
This value is a text string, using the database encoding (UTF-8, UTF-16BE or UTF-16LE) storage |
5 |
This value is a drop of data, stored completely as input. |
SQLite storage classes are more general than data types. For example, the INTEGER storage class includes6different integer data types of different lengths.
SQLite supports the concept of type similarity on columns. Any column can still store any type of data, but the preferred storage class of the column is called affinity. SQLite3Each column in the database is assigned one of the following type affinities-
Serial number | Affinity and description |
---|---|
1 |
This column uses the storage class NULL, TEXT, or BLOB to store all data. |
2 |
This column may contain values using all five storage classes. |
3 |
It behaves the same as a column with NUMERIC affinity, but with the exception of CAST expressions. |
4 |
It behaves like a column with NUMERIC affinity, except that it forces integer values to be converted to floating-point representation. |
5 |
Columns with affinity of NONE do not prefer one storage class over another and do not attempt to force data from one storage class to another. |
The following table lists the names of various data types, which can be used in SQLite3when defining a table.
data type | affinity |
---|---|
| INTEGER |
| TEXT |
| NONE |
| REAL |
| NUMERIC |
SQLite does not have a separate boolean storage class. Instead, boolean values are stored as integers 0(false) and1(true).
SQLite does not have a type for storing dates and/Or store the date and time separately as a storage class, but SQLite can store dates and times as TEXT, REAL, or INTEGER values.
Serial number | Storage classes and date formats |
---|---|
1 |
The date format is 'YYYY'-MM-DD HH:MM:SS.SSS |
2 |
B.C.4714Year11Month24Days since noon at Greenwich on the day |
3 |
Since1970-01-01 Seconds since 00:00:00 UTC |
You can choose to store dates and times in these formats and freely convert between them using built-in date and time functions.