user3142622 user3142622 - 20 days ago 5
MySQL Question

uknown column in field list trigger

What is the issue here? I'm using workbench. When i try to insert into my table staff i get an error.

I'm trying to insert into another table values from the ;staff' depending if on an input to the one of the columns.

Error Code: 1054. Unknown column 'position' in 'field list' 0.046 sec


CREATE TRIGGER your_trigger_name
AFTER INSERT ON staff
FOR EACH ROW
BEGIN
if position = 'senior instructor'
then
INSERT INTO NEW.senior_instructor
VALUES (NEW.employee_name, NEW.date_of_birth);

end if;
END;

Answer
delimiter ||

CREATE TRIGGER your_trigger_name
    AFTER INSERT ON staff
    FOR EACH ROW 
BEGIN
   if NEW.position = 'senior instructor' 
   then
       INSERT INTO senior_instructor 
       VALUES (NEW.employee_name, NEW.date_of_birth);

    end if;
END
||
delimiter ;