You get a bonus - 1 coin for daily activity. Now you have 1 coin

Cant update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger

Practice




Can't update table '' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
you most likely tried to change or delete data in the same table on which the trigger fired

this isn't allowed in mysql, but there is a way to write it

like this

CREATE DEFINER = 'root'@'127.0.0.1' TRIGGER `editstatus` BEFORE INSERT ON `user`
FOR EACH ROW BEGIN

SET new.status = 1;

END;

instead of



CREATE
DEFINER = 'root'@'127.0.0.1'
TRIGGER editstatus
AFTER UPDATE
ON user
FOR EACH ROW
BEGIN
INSERT INTO user SET status = 1;
END


then you'll be able to change data in the table on which the trigger fires
you can only change a field on insert in the trigger before the insert happens ::biggrin24.gif:: and only the current field
, but unfortunately reading data from and writing to the table on which the trigger fired isn't possible yet in mysql

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)