如何在 MYSQL 中设置列​​的最大值?

How do I set Maximum Value of a Column in MYSQL?

我有Table叫WORKERS,Table由totalNumberOfWorkers组成,我想设置worker的最大值为30,不能超过30,应该介于 0 到 30 之间。

我已经试过了,但它不起作用并显示错误,我的代码不正确。

ALTER TABLE WORKERS
CONSTRAINT WORKERS_CHECK CHECK (totalNumberOfWorkers => 0 AND totalNumberOfWorkers <31);

这里是 Table 所谓的 WORKERS

+------------------------+-------------+------+-----+---------+-------+
| Field                  | Type        | Null | Key | Default | Extra |
+------------------------+-------------+------+-----+---------+-------+
| WorkerID               | int(6)      | NO   | PRI | NULL    |       |
| dateOfWork             | date        | NO   |     | NULL    |       |
| timeOfWork             | time        | NO   |     | NULL    |       |
| descOfWorker           | varchar(50) | NO   |     | NULL    |       |
| totalNumberOfWorkers   | int(2)      | NO   |     | NULL    |       |
+------------------------+-------------+------+-----+---------+-------+

找到解决方案

ALTER TABLE WORKERS
ADD CONSTRAINT TOTALNUMBER_CHECK1 CHECK(totalNumberOfWorkers BETWEEN 1 AND 30);