Jump to content

Something trigger for update other table with some condition


deib97
Go to solution Solved by 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

Link to comment
Share on other sites

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 by deib97
Link to comment
Share on other sites

  • Solution
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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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