Thursday, March 9, 2017

MySQL Trigger After Update

Trigger update diri sendiri:
=============================
CREATE TRIGGER upd_periode BEFORE UPDATE ON tworklist
FOR EACH ROW
BEGIN
    SET new.periode = DATE_FORMAT(new.Date,'%M %Y');
END

CREATE TRIGGER upd_periode BEFORE UPDATE ON tworklist
FOR EACH ROW
BEGIN
    set new.normNeeds=new.area*new.rate*new.perRate*new.rotasi;
END


CREATE TRIGGER inst_periode BEFORE INSERT ON tworklist
FOR EACH ROW
BEGIN
    SET new.periode = DATE_FORMAT(new.Date,'%M %Y');
END


Trigger update ke tabel yang lain:
===================================
DELIMITER $$
CREATE TRIGGER update_area AFTER UPDATE ON _calcnorm
FOR EACH ROW
  BEGIN
      UPDATE _calcnorm_detail SET area = NEW.workArea WHERE id_calcnorm = NEW.id;
 END $$   

No comments:

Post a Comment