deib97 Posted January 24, 2014 Share Posted January 24, 2014 Hi, i have 2 table, a table alat and a table mutasi_alat. Every I do action insert to the table mutasi_alat, with a relation alat.id_alat and insert date newer then the value that is in the table mutasi_alat.id_cabang. The table will trigger an update to the table alat.cabang_terakhir. Table 1 : alat Table 2 : mutasi_alat I want to be trigger update into table alat after any action insert in table mutasi_alat. Do I have to make a single trigger or storeprocedure with this conditions? thanks Quote Link to comment Share on other sites More sharing options...
deib97 Posted January 25, 2014 Author Share Posted January 25, 2014 (edited) DROP TRIGGER IF EXISTS `auto_update_tabel_alat`; DELIMITER // CREATE TRIGGER `auto_update_tabel_alat` AFTER INSERT ON `mutasi_alat` FOR EACH ROW update alat set cabang_terakhir=NEW.id_cabang where id=NEW.id_alat // DELIMITER ; Still not complete.. Edited January 25, 2014 by deib97 Quote Link to comment Share on other sites More sharing options...
Solution deib97 Posted January 28, 2014 Author Solution Share Posted January 28, 2014 DROP TRIGGER IF EXISTS `auto_update_tabel_alat`; DELIMITER // CREATE TRIGGER `auto_update_tabel_alat` AFTER INSERT ON `mutasi_alat` FOR EACH ROW update alat set cabang_terakhir=(SELECT mutasi_alat.id_cabang FROM mutasi_alat where mutasi_alat.tgl_berlaku=(select max(mutasi_alat.tgl_berlaku) from mutasi_alat where id_alat=NEW.id_alat)) where id=NEW.id_alat // DELIMITER ; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.