0

In the error console it displays :

Error Code: 1442. Can't update table 'warriors' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

This is my table :

This is the Table in which the trigger is set

This is the trigger creation statement:

create trigger power_update
after update on   warriors 
 for each row update warriors 
set power = (practise_hours * 100);

This is the statement to update the table

update warriors set practise_hours = 80 where id = 9;
Shadow
  • 33,525
  • 10
  • 51
  • 64
Ronit Pandey
  • 153
  • 1
  • 8

1 Answers1

1

This should Work Fine in MySQL

DELIMITER //

CREATE TRIGGER update_power BEFORE UPDATE ON warriors
FOR EACH ROW
BEGIN
  SET NEW.powers = NEW.practice_hours * 100;
END //

DELIMITER ;

You have to use the NEW keyword to reference the updated values combined with a BEFORE trigger since the AFTER cannot modify the NEW row values.

DELIMITER allows us to change the default delimiter ;

However, a Generated/Computed Column might be a better solution.

Bala
  • 11
  • 2