Home > Database > Mysql Tutorial > mysql-Mysql数据库触发器执行不成功

mysql-Mysql数据库触发器执行不成功

PHPz
Release: 2019-02-25 17:50:00
Original
1985 people have browsed it

相关mysql视频教程推荐:《mysql教程

  • Mysql数据库中有order、orderitem和goods三张表,其中order与orderitem通过order的ID字段与orderitem的orderid字段关联;其中goods与orderitem通过goods的ID字段与orderitem的goodsid字段关联;

  • 现在想做一个触发器,当一个订单被确认的时候,该订单中所有产品的剩余数量和出售数量做相应的改变,order表isvalid字段的值有其他值变为Y的时候更新goods表中store和salecount值,请问写入下的触发器为什么不能实现目的呢,另外在脚本中提示已经创建成功怎么通过SELECT * FROM information_schema.TRIGGERS;查询不到触发器呢?

  • delimiter ||
    drop trigger if exists updatestore||
    create trigger updatestore after update on order for each row
    begin
     declare numorder int(11);
     set numorder = (select count(count) from orderitem where orderid = old.id);
     if new.isvalid ='Y' and old.isvalid !='Y' then
      update goods set store = store - @numorder, salecount = salecount + @numorder where id in (select goodsid from zsorderitem where orderid = old.id);
     end if;
     if new.isvalid !='Y' and old.isvalid ='Y' then
      update goods set store = store + @numorder, salecount = salecount - @numorder where id in (select goodsid from orderitem where orderid = old.id);
     end if;
    end||
    Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template