📅  最后修改于: 2020-11-12 09:36:30             🧑  作者: Mango
SQLite数据类型用于指定任何对象的数据类型。每个列,变量和表达式在SQLite中都有相关的数据类型。这些数据类型在创建表时使用。 SQLite使用更通用的动态类型系统。在SQLite中,值的数据类型与值本身(而不是其容器)相关联。
SQLite存储类
SQLite数据库中的存储值具有以下存储类别之一:
Storage Class | Description |
---|---|
NULL | It specifies that the value is a null value. |
INTEGER | It specifies the value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. |
REAL | It specifies the value is a floating point value, stored as an 8-byte IEEE floating point number. |
text | It specifies the value is a text string, stored using the database encoding (utf-8, utf-16be or utf-16le) |
BLOB | It specifies the value is a blob of data, stored exactly as it was input. |
注意:SQLite存储类比数据类型更通用。例如:INTEGER存储类包括6种不同长度的不同整数数据类型。
SQLite支持列的类型相似性。任何列仍然可以存储任何类型的数据,但是列的首选存储类称为亲和力。
在SQLite3数据库中有用于分配的以下类型关联。
Affinity | Description |
---|---|
TEXT | This column is used to store all data using storage classes NULL, TEXT or BLOB. |
NUMERIC | This column may contain values using all five storage classes. |
INTEGER | It behaves the same as a column with numeric affinity with an exception in a cast expression. |
REAL | It behaves like a column with numeric affinity except that it forces integer values into floating point representation |
NONE | A column with affinity NONE does not prefer one storage class over another and don’t persuade data from one storage class into another. |
以下是创建SQLite表时可以使用的各种数据类型名称的列表。
Data Types | Corresponding Affinity |
---|---|
INT INTEGER TINYINT SMALLINT MEDIUMINT BIGINT UNSIGNED BIG INT INT2 INT8 |
INTEGER |
CHARACTER(20) VARCHAR(255) VARYING CHARACTER(255) NCHAR(55) NATIVE CHARACTER(70) NVARCHAR(100) TEXT CLOB |
TEXT |
BLOB no datatype specified |
NONE |
REAL DOUBLE DOUBLE PRECISION FLOAT |
REAL |
NUMERIC DECIMAL(10,5) BOOLEAN DATE DATETIME |
NUMERIC |
在SQLite中,没有单独的类来存储日期和时间。但是您可以将日期和时间存储为TEXT,REAL或INTEGER值。
Storage Class | Date Format |
---|---|
TEXT | It specifies a date in a format like “yyyy-mm-dd hh:mm:ss.sss”. |
REAL | It specifies the number of days since noon in Greenwich on November 24, 4714 B.C. |
INTEGER | It specifies the number of seconds since 1970-01-01 00:00:00 utc. |
在SQLite中,没有单独的布尔存储类。相反,布尔值存储为整数0(假)和1(真)。