The Versatile Check Constraint
If constraints can be considered “cool,” then the check constraint[85] has to be the coolest. This is a flexible type of constraint you’ll use in multiple ways.
Any condition that you can express using SQL that evaluates to a Boolean result can be written for a check constraint. There are caveats. The scope for a check constraint is only the current row and current table, not other rows or other tables, and can only work with the row data being input.
Like other types you’ve seen so far, check constraints are added to a table.
For Rails developers, you’ll want to know that support for check constraints was added to Active Record in version 6.1,[86] and support for if_exists was added later.[87] This means helper ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access