mysql 触发器

begin
SELECT a.location,a.flag into @loc,@flag FROM workdrawmst a where a.no=new.no;
select count(*) into @c from locstock where  loccode=@loc and stockid=new.stockid;
if @c<1 then
insert into locstock (loccode,stockid,quantity) values (@loc,new.stockid,-@flag*new.qty);
else
update locstock set quantity=quantity-@flag*new.qty where loccode=@loc and stockid=new.stockid;
end if;
end
原文地址:https://www.cnblogs.com/nbalive2001/p/2287234.html