我想在我的Oracle数据库中有一个表,其中的值attribute1
(值可能会改变)不能大于的值(固定)attribute2
。
可以执行这样的规则吗?插入后是否有可能使值无法更改?
不允许attribute1
比attribute2
使用check
约束可以做的大:
ALTER TABLE mytable
ADD CONSTRAINT attribute2_greater_check
CHECK (attribute2 >= attribute1)
attribute2
可以使用trigger
引发错误来阻止的更新:
CREATE OR REPLACE TRIGGER mytable_attribute2_update_tr
BEFORE UPDATE ON mytable
FOR EACH ROW
BEGIN
IF :NEW.attribute2 != :OLD.attribute2
THEN
RAISE_APPLICATION_ERROR(-20101, 'attribute2 cannot be updated');
END IF;
END;
/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句