I’m trying to find the most effecient way of inserting data into another table when a particular field is updated on trigger table. The INSERT should only occur on a specific type of update.
The table on which I want to create the trigger is named incremental. The table I’m inserting into is named crm_record
On incremental there is a field called status. By default when a record is initially added to the table the status field is set to new. After billing has processed that value changes to processed. So once this occurs I want to INSERT into crm_record, only if the value of another field (success) is set to 1.
I have considered using both CASE and IF but would like an expert’s opinion on the best way to do this.
All you need to do is to create an
AFTER UPDATEtrigger and test the value ofstatusandsuccesstogether. If it’s going only going to be one state you’re testing for then anIFstatement 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_recordshouldn’t actually be inserted via the code logic when thestatusandsuccesscolumns are updated.