我想在删除后将触发器插入到另一个表中。我有3张桌子(A,B,C)。如果我从表A中删除,则表B中与表A相关的记录将移至表C。
我已经尝试过了,
create trigger deleteA after delete on A
-> for each row
-> begin
-> insert into C (PKid_A,id_B)
->在这里,我想将B值插入C
-> values
-> (old.PKid_A, old.id_B);
-> end//
但是,它不起作用
答案 0 :(得分:0)
我认为您错过了A和B之间的连接,因此它将采用与A相关的那些值并将其插入表C
例如
CREATE TRIGGER triggername AFTER DELETE on A
FOR EACH ROW
BEGIN
INSERT INTO C
([c.columnname], [c.columnname])
SELECT
[B.columnname],[B.columnname] from B inner join on
A on B.id = old.id;
END