SQLite Forum

CHECK violation during table definition ignored, normal or bug?
Login
> (Implementing this seem like it would not be too complicated, as long as the CHECK constraint refers only to the column being added and not other columns; ...

A [CHECK constraint](https://sqlite.org/lang_createtable.html#ckconst) acts just like a table constraint, and can refer to other columns in the same row. [a] Hence, it can be arbitrarily complex, refer to any column in the same table, and require function calls [b], making that limitation on what could be checked problematic, and making a sanity check upon the DDL useless or counter-productive.

[a. This "same row" limitation follows from the exclusion of subqueries in the check expression. ]

[b. These functions would not be limited to pure functions; their results could depend on context or history, either of which could differ at INSERT or UPDATE time from ALTER or CREATE TABLE time. ]

I should have written, "In a fantastical, unrealizable world, ..."