mysql 触发器更新自己表|单表操作 阿星小栈
#更新表`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.
转自:http://blog.csdn.net/webnoties/article/details/47728363