我有一个名为WORKERS的表,该表由totalNumberOfWorkers组成,我想将worker的最大值设置为30,并且不应超过30,它的范围应在0到30之间。 / p>
我已经尝试过了,但是它不起作用并显示错误,我的代码不正确。
ALTER TABLE WORKERS
CONSTRAINT WORKERS_CHECK CHECK (totalNumberOfWorkers => 0 AND totalNumberOfWorkers <31);
以下是称为“工作人员”的表
+------------------------+-------------+------+-----+---------+-------+
| 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 | |
+------------------------+-------------+------+-----+---------+-------+
答案 0 :(得分:1)
找到了解决方案
ALTER TABLE WORKERS
ADD CONSTRAINT TOTALNUMBER_CHECK1 CHECK(totalNumberOfWorkers BETWEEN 1 AND 30);