I have this trigger to update a single field in a journal table after each update, but I need to update ALL columns in related row in journal at once, not by naming each of them and separating by comma, how can I do that?
DELIMITER //
CREATE TRIGGER sfo_clone_update_subtotal_invoiced AFTER UPDATE ON sales_flat_order
FOR EACH ROW BEGIN
update sales_flat_order_journal set subtotal_invoiced=NEW.subtotal_invoiced where entity_id=new.entity_id;
END;
DELIMITER ;
UPDATE syntax allows you to set multiple columns, separated by commas.
You can access
NEW.other_columnto get the values of the same row that spawned the trigger.You can DECLARE local variables in your trigger body to help calculate complex values.
You can use
SELECTstatements in your trigger body to query values from other rows or other tables, as long as you use a scalarSELECTthat returns one row and one column.If you need a more complex update that's too difficult to do in a trigger, I would do that in application code, not a trigger.