[SOLVED] the trigger with "if-elseif" does not update the table

Issue

so, made a trigger for "picks" table strong text

    delimiter //
create trigger picks_description after insert on picks
for each row
begin
if (new.Picks_Thickness between 0.5 and 0.74) then
insert into Picks (Picks_Desc) values ('медиатор для быстрой игры/ведущей гитары');
elseif (new.Picks_Thickness between 0.87 and 3) then
insert into Picks (Picks_Desc) values ('медиатор для тяжелой игры/ритм-гитары');
end if;
end //

and basically after i try to insert new info, it doesnt update the column Picks_desc

Solution

You need a before insert trigger and a SET syntax

DELIMITER //
CREATE TRIGGER picks_description BEFORE INSERT ON picks
FOR EACH ROW
BEGIN
IF (new.Picks_Thickness between 0.5 and 0.74) THEN
    SET NEW.Picks_Desc = 'медиатор для быстрой игры/ведущей гитары';
ELSEIF (new.Picks_Thickness between 0.87 and 3) then
    SET NEw.Picks_Desc = 'медиатор для тяжелой игры/ритм-гитары';
END IF;
END //

Answered By – nbk

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published.