MySQL Sample Trigger

1.Create TRIGGER BEFORE INSERT ON table
Example 1:
DELIMITER $$

CREATE TRIGGER trg_schema_return BEFORE INSERT ON carried
FOR EACH ROW BEGIN
IF (NEW.carried_return IS NULL) THEN
SET NEW.carried_return = NEW.carried_ outbound;
END IF;
END$$

Example 2:
DELIMITER $$

CREATE TRIGGER trg_used_cost BEFORE INSERT ON used
FOR EACH ROW BEGIN
SET NEW.used_charge = NEW.used_ quantity * (SELECT chem_unit_cost FROM chemical WHERE chem._num = NEW.chem_num);
END$$

2.Create TRIGGER AFTER INSERT ON table
DELIMITER $$

CREATE TRIGGER trg_ job _ charge AFTER INSERT ON used
FOR EACH ROW BEGIN
IF (NEW.used_charge <> OLD.used_charge) THEN
SET job.job_charge = NEW.used_charge;
END IF;
END$$

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.