MySQL DatabaseLesson 57Free preview
MySQL Check
This lesson is part of MySQL · All levels
Summary
Constraint CHECK limits the value of the column based on a condition, e.g. price must not be negative or minimum zero stock. MySQL started to fully enforce CHECK since version 8.0.16; previously the constraint was only syntax-checked. If any data violates the CHECK conditions, the INSERT or UPDATE operation will be denied.
Key points
- CHECK rejects a value that does not meet the written conditions
- Can be written per column when CREATE TABLE or added via ALTER TABLE
- MySQL 8.0.16+ enables CHECK, the older version only marches without enabling
- The CHECK condition can refer to a single column or a combination of columns within a row
- The name constraint CHECK makes it easier to identify when an error occurs
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.