mysql 触发器更新自己表|单表操作

时间:2021-08-06 11:02:40


#更新表`m_order`的status_id,
#注意要用BEFORE
#SQL语句不能用UPDATE,要用SET
CREATE TRIGGER `tg_order2order_update` BEFORE UPDATE ON `m_order` FOR EACH ROW BEGIN 
	set new.`status_id` = (SELECT `status_id`  FROM m_status WHERE `id` =  new.`order_id`) ;
END;

常会报错如:

updating of new row is not allowed in after trigger


Can’t update table ‘dept’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.