这是我的代码,我不知道这有什么不对:
CREATE TRIGGER trigger_before_insert_instruments
BEFORE INSERT ON Instruments
FOR EACH ROW
WHEN (NEW.type NOT IN (SELECT type FROM Types))
EXECUTE PROCEDURE
insert_new_type_or_famille();
但是控制台给我一个像&#34这样的错误;你可以在when条件下使用子查询......
答案 0 :(得分:1)
在触发器正文中使用if
。这看起来像这样:
CREATE TRIGGER trigger_before_insert_instruments
BEFORE INSERT ON Instruments
FOR EACH ROW
BEGIN
IF NOT EXISTS (SELECT 1 FROM Types WHERE :NEW.type = t.Types) THEN
EXECUTE PROCEDURE insert_new_type_or_famille();
END IF;
END;