登录

mysql触发器问题

看了数据库的触发器,就想,如果某个定单表插入的数量大于商品表,那么商品表应该是负数啊,应该加以限制。可是我采用before来限制时,则不能执行,谁帮我看下这串代码哪错了

create trigger tg1

before insert on ord

for each row

begin

if new.o_num > goods.g_num then

set new.o_num = goods.g_num

end if;

update goods set g_num = g_num - new.o_num where gid = new.gid;

end$

# PHP
覃斌 覃斌 2083 天前 1076 次浏览

全部回复(2) 我要回复

  • ll

    ll2018-08-13 17:36:39

    if new.o_num > goods.g_num then

    set new.o_num = goods.g_num

    当DD的数量大于库存数量 你让DD的数量等于库存的数量了 你可以用phpmyadmin来建触发器

    回复
    0
  • ll

    ll2018-08-13 17:34:09

    你这个也不需要 触发器来做 买之前 限制买的数量

    回复
    0
  • 取消 回复 发送