Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Table Goods_has_Taker(order_id,good_id...)
  2. Table Goods (good_id, price...)
  3. Table OrderD (order_id, transaction_date, amount)
  4.  
  5. CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`OrderD_BEFORE_INSERT`
  6. BEFORE INSERT ON `OrderD` FOR EACH ROW
  7. BEGIN
  8. DECLARE quantity Int;
  9. declare price FLoat;
  10.  
  11. set new.transaction_date=NOW(),
  12. @quantity :=
  13. (select out_quantity from Goods_has_Taker
  14. where Goods_has_Taker.order_id=new.order_id),
  15. @price :=
  16. (select price from Goods
  17. Inner Join Goods_has_Taker
  18. On Goods.good_id=Goods_has_Taker.good_id
  19. Where new.order_id = Goods_has_Taker.order_id
  20. ),
  21. new.amount=@quantity*@price;
  22. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement