有两个表A,B,相同的表结构
其中有个字段type
当A表中有新增数据并且type=1的时候,触发触发器增加B表一条数据,并且将B表中的type字段设置为3,B表中也有一个触发器,当B表中有新增数据的时候,触发B表中的触发器,往A表中增加一条数据,并且将type设置为2。但是实际执行中,有问题,不知道什么原因求解
其中有个字段type
当A表中有新增数据并且type=1的时候,触发触发器增加B表一条数据,并且将B表中的type字段设置为3,B表中也有一个触发器,当B表中有新增数据的时候,触发B表中的触发器,往A表中增加一条数据,并且将type设置为2。但是实际执行中,有问题,不知道什么原因求解
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `mon_consume_trg` before INSERT ON `mon_consume_log`
FOR EACH ROW BEGIN
/*
test time setting:
from time :2008-10-01
end time: 2008-12-01
*/
if ((new.consume_time)>="2008-10-01 00:00:01" and (new.consume_time<="2008-12-01 11:59:59")) then
if (new.service_id=1) then
insert into trg_mon
(version, consume_time, service_id, status, mobile,old_service_id) values(
new.version, new.consume_time, 4, new.status, New.mobile, new.service_id);
end if;
if (new.service_id=5) then
insert into trg_mon
(version, consume_time, service_id, status, mobile,old_service_id) values(
new.version, new.consume_time, 8, new.status, New.mobile, new.service_id);
end if;
end if;
触发器B
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `trg_mon_trg` after insert ON `trg_mon`
FOR EACH ROW BEGIN
insert into mon_consume_log
(version, consume_time, service_id, status, mobile)
values(new.version, new.consume_time, 8, new.status, new.mobile);
END; END;