create trigger update_order_status after update on order_sale for each row begin declare count1 int; declare count2 int;declare status_id int ;select order_status_id from `order` where id=new.order_id into status_id; select count(id) from order_sale where order_id=new.order_id into count1; select count(id) from order_sale where order_id=new.order_id and status=18 into count2; if count1=count2 and new.status=18 and new.status<>old.status then update `order` set comment='18' where id=new.order_id; update order_status set code='18' where id=status_id; end if; end
mysql 触发器用法笔记
最新推荐文章于 2023-04-10 22:07:28 发布
本文介绍了一个MySQL触发器,用于在订单销售表更新时检查订单状态,并根据特定条件更新订单表的状态标识。触发器通过比较已完成订单数量与总订单数量来判断是否全部订单已完成。
1084

被折叠的 条评论
为什么被折叠?



