The CHECK
constraint validates that values in a column satisfy a Boolean expression.
Introduced in MySQL 8.0.16+, it helps enforce custom business rules at the database level.
column_name data_type CHECK ( boolean_expression )
CREATE TABLE accounts ( account_id INT AUTO_INCREMENT PRIMARY KEY, balance DECIMAL(10,2) CHECK (balance >= 0), status VARCHAR(10) CHECK (status IN ('active','inactive','closed')) );
ALTER TABLE users ADD CONSTRAINT chk_age CHECK (age BETWEEN 18 AND 99);
ALTER TABLE accounts DROP CHECK chk_balance;
SELECT * FROM table WHERE NOT (your_condition);
to find violations.
IN
list).end_date >= start_date
).REGEXP
(MySQL 8.0+).Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!