How to avoid inserting the wrong data type in SQLite tables? How to avoid inserting the wrong data type in SQLite tables? sqlite sqlite

How to avoid inserting the wrong data type in SQLite tables?


You can implement this using the CHECK constraint (see previous answer here). This would look like

   CREATE TABLE T (       N   INTEGER CHECK(TYPEOF(N) = 'integer'),       Str TEXT CHECK(TYPEOF(Str) = 'text'),       Dt  DATETIME CHECK(JULIANDAY(Dt) IS NOT NULL)   );


The better and safer way is write a function (isNumeric, isString, etc) that validates the user input...