嘿,我有一个在更新后触发的触发器,定义如下:
CREATE DEFINER = `root`@`localhost` TRIGGER `logs_m` AFTER UPDATE ON
`logs_month` FOR EACH ROW
BEGIN IF NEW.status =1 THEN INSERT INTO logs_payments( direction,
TYPE , amount, agent_id, invoice_number )
VALUES ( 0, 3, NEW.reward_minutes, NEW.agent_id, NULL ) ,
( 0, 5, NEW.credit, NEW.agent_id, NULL ) ;
END IF ;
END
现在logs_payments
我在插入后有一个触发器,它的定义如下:
CREATE DEFINER = `root`@`localhost` TRIGGER `payments_invoice` BEFORE INSERT ON
`logs_payments`
FOR EACH
ROW BEGIN
IF NEW.direction =0
THEN
SET NEW.invoice_number = ( SELECT MAX( IFNULL( invoice_number, 100000000 ) ) +1
FROM logs_payments l
WHERE l.direction =0 ) ;
END IF ;
IF NEW.direction =1 THEN SET NEW.invoice_number =
( SELECT MAX( IFNULL( invoice_number, 200000000 ) ) +1
FROM logs_payments l
WHERE l.direction =1 ) ;
END IF ;
END
现在插入的第一invoice_number
行为空,第二行获得正确的值。
知道为什么会这样吗?