Jump to content

Something trigger for update other table with some condition


deib97

Recommended Posts

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

tabel_alat.jpg?dl=1&token_hash=AAGypUvtY

 

Table 2 : mutasi_alat

tabel_mutasi_alat.jpg?dl=1&token_hash=AA

I want to be trigger update into table alat after any action insert in table mutasi_alat.

clue.jpg?dl=1&token_hash=AAFf3nou73ql-D4

 

Do I have to make a single trigger or storeprocedure with this conditions?

thanks

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..

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 ;

:happy-04:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.