我有一个名为的表Room
,它有列(ID、类型、价格......等)
我想为两者添加约束type
,price
例如:
- 如果是单件,则价格不应大于 50,
- 如果 double (d),则价格不应大于 100,并且
- 如果是家庭 (f),那么价格不应大于 150
我试图像这样添加它,但它给了我一个错误。不知道我应该怎么写:
ALTER TABLE ROOM
ADD (CONSTRAINT CHK_PRICE CHECK (
(TYPE='S' AND PRICE <= 50) AND
(TYPE='D' AND PRICE <=100) AND
(TYPE='F' AND PRICE <= 150)));
收到的错误是:
SQL Error: ORA-02293: cannot validate (xxxx.CHK_PRICE) - check
constraint violated
02293. 00000 - "cannot validate (%s.%s) - check constraint violated"
*Cause: an alter table operation tried to validate a check constraint to
populated table that had nocomplying values.
*Action: Obvious