Database / SQLite Interview questions
What is the difference between CHAR, VARCHAR, and TEXT in SQLite?
Functionally, all three are treated identically in SQLite — whatever length or width you declare
(CHAR(10), VARCHAR(255)) is completely ignored for storage purposes; SQLite stores
the string exactly as given, taking only as much space as the actual text requires, since it uses dynamic
typing rather than fixed-width storage.
CREATE TABLE t ( a CHAR(10), b VARCHAR(255), c TEXT ); INSERT INTO t VALUES ('hi', 'this text is way longer than expected', 'anything'); -- all three succeed with no truncation or padding; SQLite doesn't enforce the declared length
All three simply map to the TEXT storage class and affinity underneath. The length/width
number in CHAR(10) or VARCHAR(255) is accepted syntactically (for compatibility
with SQL written for other databases) but has zero effect on how SQLite actually stores or validates the
value.
More Related questions...