Showing posts with label trigger. Show all posts
Showing posts with label trigger. Show all posts

October 26, 2017

Sample Mysql Trigger on product inventory


Sample Mysql Trigger on product inventory


DELIMITER $$

DROP TRIGGER /*!50032 IF EXISTS */ `db_inventory_datacom`.`UpdateInventoryOnSalesReturn`$$

CREATE
    /*!50017 DEFINER = 'root'@'localhost' */
    TRIGGER `UpdateInventoryOnSalesReturn` AFTER INSERT ON `tbl_prdt_sales_returns`
    FOR EACH ROW begin
update tbl_inventories set prod_quantity=(prod_quantity + new.prdt_quantity),prod_reorder_date=curdate() where prod_id=new.prod_id;
    END;
$$

DELIMITER ;

The event triggers when ever a new row is inserted in  the table `tbl_prdt_sales_returns`.

The trigger will update the table  tbl_inventories  product quantity .

Facebook comments