After: is the data before and after the deletion and modification, and then triggered. Trigger the statement later than the monitoring of additions and deletions, can not affect the previous additions and deletions to modify. This means that the order record is inserted first. Update the item quantity again. When the quantity of goods is less than the number of orders caused explosion.
Before: First, after the trigger, in the additions and deletions, trigger statements before the monitoring of the additions and deletions, we have the opportunity to infer, change the action that is about to happen. Case Action:Triggerusing after:Inventory is negative when the quantity of an order exceeds the quantity in stock. caused by the so-called problem of bomb-bank.
#创建触发器test4CREATE TRIGGER Test4afterinserton ' ord ' for each rowbeginupdate goods SET num= num-new.much WHERE goods_id = n Ew.gid; end$$
Triggerusing before:Trigger first, after inference processing and then the increase and deletion will not, according to inventory changes the maximum number of orders.
Of course, I'm just simply fixing a value that can actually get a dynamic inventory value with a statement.
#创建触发器test5CREATE TRIGGER Test5beforeinserton ' ord ' for each rowbegin IF new.much >26 then SET New.much = 26;
end IF; UPDATE goods SET num= num-new.much WHERE goods_id = New.gid; end$$
MySQL trigger trigger after and before distinguish