– 直接运行即可
– 当商品上下架状态更新时,记录到另一个表中
DROP TRIGGER IF EXISTS updatetbl_slope;-- 删除原先的触发器
CREATE trigger updatetbl_slope
AFTER update-- 表示触发器是在激活它的语句之后触发
on aa_product
for each row -- mysql固定语法
BEGIN
IF new.IsOnSell <> old.IsOnSell
then
if EXISTS(SELECT * FROM aa_isonsell WHERE ProId=old.ProId LIMIT 1)
THEN
update aa_isonsell set IsOnSell=new.IsOnSell where ProId=old.ProId;
else
insert into aa_isonsell(ProId,IsOnSell) VALUES(old.ProId,new.IsOnSell);
END IF;
END IF;
END
参考文档:
https://blog.csdn.net/qq_36020545/article/details/76502233
https://blog.csdn.net/weixin_30412167/article/details/96470305