我创建了一个工作正常的触发器。
CREATE TRIGGER INSERT_USERID_TO_PERMISSIONS_TABLES
AFTER INSERT ON ALLUSERS
REFERENCING NEW AS NEW_USERID_ROW
FOR EACH ROW MODE DB2SQL
INSERT INTO ALLUSERS_HOMEPERMISSIONS(USERID)
VALUES(NEW_USERID_ROW.USERID);
然后我删除它以重新创建一个包含2个INSERT
语句的新版本。当我添加其他INSERT
语句时,它会失败并返回错误。我知道我错过了一些语法错误或关键字。我用Google搜索了它,但无法获得与Derby等效的BEGIN and END
(在MSSQL中)。
如果我这样做,
CREATE TRIGGER INSERT_USERID_TO_PERMISSIONS_TABLES
AFTER INSERT ON ALLUSERS
REFERENCING NEW AS NEW_USERID_ROW
FOR EACH ROW MODE DB2SQL
INSERT INTO ALLUSERS_HOMEPERMISSIONS(USERID) --1st insert
VALUES(NEW_USERID_ROW.USERID);
INSERT INTO ALLUSERS_ADMIN_PERMISSIONS(USERID)-- 2nd insert
VALUES(NEW_USERID_ROW.USERID);
它会返回错误。
我想也许我可以添加BEGIN
和END
CREATE TRIGGER INSERT_USERID_TO_PERMISSIONS_TABLES
AFTER INSERT ON ALLUSERS
REFERENCING NEW AS NEW_USERID_ROW
FOR EACH ROW MODE DB2SQL
BEGIN
INSERT INTO ALLUSERS_HOMEPERMISSIONS(USERID) --1st insert
VALUES(NEW_USERID_ROW.USERID);
INSERT INTO ALLUSERS_ADMIN_PERMISSIONS(USERID)-- 2nd insert
VALUES(NEW_USERID_ROW.USERID);
END
我很感激任何帮助。
感谢。