W3Schools says:
The CHECK constraint is used to limit the value range that can be
placed in a column.If we define a CHECK constraint on a single column it allows only certain
values for this column.If we define a CHECK constraint on a table it can limit the values in
certain columns based on values in
other columns in the row.
From designing a web application perspective, adding this constraint on the DB certainly help me avoiding data corruption and additional level of validation for checking field level data can be avoided in Validation layer of my web application. The only problem I see here is that error message returned from database is not meaningful that can be shown to the end user.
What do you say about this? Or I would ask, in what scenario you’ve used this constraint?
The check constraints (as other constraints) are there to guarantee an additional level of coherence, but they must not be used to replace the validation logic in your app, which should, as you mention, display meaningful error messages, and be done (at least) in the presentation layer, before hitting the database.
Even if they might seem like a duplication of the validation logic, constraints are still useful because