Database / SQLite Interview questions
What is dynamic typing (type affinity) in SQLite?
SQLite uses type affinity rather than strict column typing: a column's declared type is a preference for how to store a value, not a hard constraint that rejects mismatched data the way most databases enforce. Each column is assigned one of five affinities (TEXT, NUMERIC, INTEGER, REAL, BLOB) based on keywords in its declared type, and SQLite tries to convert an inserted value to match that affinity, but will still store the value as-is if conversion isn't sensible.
CREATE TABLE t (a INTEGER); INSERT INTO t VALUES ('hello'); -- succeeds! 'hello' has no numeric form, so it's stored as TEXT
This flexibility is a deliberate design choice for SQLite's typical embedded use cases, but it's also a common surprise for developers coming from strictly-typed databases, who expect a type mismatch to raise an error rather than being silently accepted and stored in its original form.
More Related questions...