我正在尝试为 table3 创建触发器以插入新行我有关于触发器的基本信息这就是我试图做的但是我被错误执行中断了
delimiter #
create trigger TABLE3_INSERT_TRIGGER after insert on table2
for each row
begin
insert into table3 (tableZ_ID, table2_ID) values (new.tableZ_ID, new.table2_ID);
end#
delimiter ;
+------------+ | tableZero | +------------+ |tableZ_ID(PK| +------------+ |tableZ_Name | +------------+ |table1_ID(FK| +------------+ +------------+ | table1 | +------------+ |table1_ID(PK| +------------+ |table1_Name | +------------+ +------------+ | table2 | +------------+ |table2(PK) | +------------+ |table1 (FK) | +------------+ |table2Info | +------------+ +------------+ | table3 | +------------+ |tableZ_ID(FK| +------------+ |table2_ID(FK| +------------+
最佳答案
根据您的表设计,tableZero 中必须有数据可用,否则会给出与引用键相关的错误。
表 1 -> 表 0
如果需要更多信息,请告诉我
关于mysql - 如何为嵌套表创建触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359125/