字符串 - Varchar - SQLite 数据类型

String - Varchar - SQLite datatypes

在 SQLite 中,String - varchar 谁能说出这两者之间的确切区别?

除非您使用的是 BLOB,否则 SQLite 中的所有字符串数据类型都会转换为 TEXT 数据类型,因为 SQLite 不允许对字符串数据类型进行大小限制。

SQLite 使用 dynamic typing;声明的数据类型的名称无关紧要:

CREATE TABLE MyTable (
    Col1 TEXT,           -- this is stored as a text value
    Col2 STRING,         -- so is this
    Col3 VARCHAR(1),     -- and this
    Col4 FLUFFY BUNNIES, -- and this
    Col5,                -- and this
    Col6 INTEGER         -- and this, if the actual value is not a number
);

声明的长度也被忽略(查询计划器仅使用它来估计 I/O 的数量)。

要强制执行数据类型或长度,您需要一个单独的 CHECK 约束:.

CREATE TABLE MyTable (
    Col7 TEXT NOT NULL  CHECK(typeof(Col7) = 'text')
);