(root@node01) > create table student (
id int primary key,
name varchar(255),
age int,
gender char(1),
score float,
constraint chk_age check (age>= 18),
constraint chk_score check (score>= 0 and score<=100)
);
Query OK, 0 rows affected (0.20 sec)
(root@node01) > insert into student(id, name, age, gender, score) values (1, "tom", 16, "m", 89.5);
ERROR 3819 (HY000): Check constraint 'chk_age' is violated.
(root@node01) > insert into student(id, name, age, gender, score) values (1, "tom", 19, "m", 89.5);
Query OK, 1 row affected (0.05 sec)
标签:8.0,name,age,chk,id,score,student,MySQL,CHECK
From: https://blog.51cto.com/dbprofessional/7245511