在删除 T_QUESTION 表的记录时 同时删除T_OPTION下的相关记录
- SQL code
CREATE TRIGGER DB2ADMIN.T_QUT_DEL_TR BEFORE DELETE ON DB2ADMIN.T_QUESTION FOR EACH ROW MODE DB2SQL BEGIN ATOMIC DELETE FROM DB2ADMIN.T_OPTION WHERE QUTID = CURRENT QUTID;END
------解决方案--------------------------------------------------------
看来看去没什么错误啊 DB2ADMIN.T_OPTION.QUTID试试看 不过你可以用添加外键并指定cascade方式删除相关信息
------解决方案--------------------------------------------------------
在前置(before)触发器不能对其他表进行DML操作(例如insert,update,delete),前置触发器必须用no cascade before,另外还有后置(after)触发器和instead of触发器
同步删除要用后置触发器
- SQL code
CREATE TRIGGER DB2ADMIN.T_QUT_DEL_TR AFTER DELETE ON DB2ADMIN.T_QUESTION REFERENCING OLD AS O_ROW FOR EACH ROW MODE DB2SQL DELETE FROM DB2ADMIN.T_OPTION WHERE QUTID = O_ROW.QUTID;