使用TRIGGER,我想删除table2中具有与id在table1中删除的行相同的ID的行
CREATE TRIGGER trgDeleteInTable2 AFTER DELETE ON table1
FOR EACH ROW
BEGIN
DELETE FROM table2 a WHERE a.id = the same id than the one deleted in table1
END;
我该怎么办?如何获取表1中删除的当前ID?
感谢您的帮助
答案 0 :(得分:1)
尝试一下:
CREATE TRIGGER trgDeleteInTable2 AFTER DELETE ON table1
FOR EACH ROW
BEGIN
DELETE * FROM table2 a WHERE a.id = OLD.id
END;
OLD.id
是已被删除的id
中的table1
。