KaviSuja
KaviSuja

Reputation: 450

String - Varchar - SQLite datatypes

In SQLite, String - varchar can anyone tell the exact difference between both of this?

Upvotes: 0

Views: 3616

Answers (2)

CL.
CL.

Reputation: 180060

SQLite uses dynamic typing; the name of the declared data type does not matter:

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

The declared length is ignored, too (it's used only by the query planner to estimate the amount of I/O).

To enforce data types or lengths, you would need a separate CHECK constraint:.

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

Upvotes: 2

Paul
Paul

Reputation: 1041

All string datatypes in SQLite are converted to a TEXT datatype unless you're using a BLOB, because SQLite does not allow size restrictions on string datatypes.

Upvotes: 0

Related Questions