MySQL Trigger - INSERT on condition of UPDATE?

All you need to do is to create an AFTER UPDATE trigger and test the value of status and success together. If it's going only going to be one state you're testing for then an IF statement would be the simplest way to go about it.

All you need to do is to create an AFTER UPDATE trigger and test the value of status and success together. If it's going only going to be one state you're testing for then an IF statement would be the simplest way to go about it. However before implementing a trigger it's always worth going back a step and checking to see if the row in crm_record shouldn't actually be inserted via the code logic when the status and success columns are updated.

Thanks Ira, I will write up the code and post back here with my results – Michael May 19 at 8:38.

Ok, I eventually went with this that seemed to work. Thanks for pointing me in the right direction CREATE TRIGGER `incremental5_after_ins_tr_crmm` AFTER UPDATE ON `incremental5` FOR EACH ROW BEGIN IF Status = 'processed' AND Success = 1 THEN INSERT INTO crm_master (msisdn,source,contract_type,revenue) VALUE (new. Msisdn,'INC5',new.

Contract_type,revenue=revenue+2.5) ON DUPLICATE KEY UPDATE contract_type=new. Contract_type,revenue=revenue+2.5; END IF; END.

You cannot cancel the update. I would keep table with versions separately from the "main" table, and would insert into this table new record when main table gets updated. Or even easier - use insert with new version number instead of update without any triggers.

Thank you for your answer. I will go for a separate table. I prefer not to rely on people using insert with new version number, this is error prone.

– Barth Aug 26 '10 at 8:18 Agree. If you are not the exclusive owner of the code, separate table is safer. – spbfox Aug 26 '10 at 8:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions