零件( pid ,pname,颜色) 供应商( sid ,sname,地址) 目录( sid,pid ,价格)
SQL触发器 - 没有供应商可以提供绿色和红色部件
到目前为止我有什么
CREATE TRIGGER NoRedAndGreenParts
BEFORE INSERT ON Parts
REFERENCING NEW ROW AS N
FOR EACH ROW
WHEN NOT EXISTS
( SELECT * FROM Parts P1 WHERE N.pid = P1.pid AND P1.color = 'red' AND EXISTS
( SELECT * FROM Catalog C1, Parts P2 WHERE C1.sid = N.sid AND C1.pid = P2.pid AND P2.color = 'green' )
INTERSECT
( SELECT * FROM Parts P3 WHERE N.pid = P3.pid AND P3.color = 'green' AND EXISTS
( SELECT * FROM Catalog C2, Parts P4 WHERE C2.sid = N.sid AND C2.pid = P4.pid AND P4.color = 'red' )
);
尝试了以下触发器,但在预期时它不起作用。究竟是什么问题?
编辑:
如果供应商在供应红色部件时突然决定供应绿色部件,我试图阻止插入表中
即。供应商只能提供红色或绿色部件,但不能同时提供