Oracle 11g – Check constraint with RegEx

A check constraint follows the same syntax rules as conditions for a WHERE clause: alter table foo add constraint check_email check (REGEXP_LIKE(email,’your_regex_goes_here’,’I’)); More details in the manual: for Oracle 11 – http://docs.oracle.com/cd/E11882_01/server.112/e41084/conditions007.htm#SQLRF52141 for Oracle 12 – https://docs.oracle.com/database/121/SQLRF/conditions007.htm#SQLRF52141 Edit: There are however some restrictions on what you can actually use in a check constraint: Oracle 11 … Read more

SQL Sub queries in check constraint

It is not supported to look beyond the current row in a CHECK constraint. http://www.postgresql.org/docs/9.1/interactive/sql-createtable.html says: A check constraint specified as a column constraint should reference that column’s value only, while an expression appearing in a table constraint can reference multiple columns. Currently, CHECK expressions cannot contain subqueries nor refer to variables other than columns … Read more

CHECK constraint in MySQL is not working

MySQL 8.0.16 is the first version that supports CHECK constraints. Read https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html If you use MySQL 8.0.15 or earlier, the MySQL Reference Manual says: The CHECK clause is parsed but ignored by all storage engines. Try a trigger… mysql> delimiter // mysql> CREATE TRIGGER trig_sd_check BEFORE INSERT ON Customer -> FOR EACH ROW -> BEGIN … Read more