String - Varchar - SQLite数据类型

时间:2016-10-19 15:49:18

标签: sql string sqlite varchar

在SQLite中,String - varchar可以告诉两者这两者之间的确切区别吗?

2 个答案:

答案 0 :(得分:1)

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')
);

答案 1 :(得分:0)

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