[ad_1]
i am trying to trigger in my SQL checking a few online info I created this trigger could you suggest me the changes I need to make or the right solution for my situation
create trigger emp_trigger after insert on emp for each row
begin
if emp_pos="trainee" then
insert into emp (emp_sal) value (5000.00),
(JSON_OBJECT(
"dmltype", NEW.dmltype,
"title", NEW.title,
"begdate", NEW.begdate,
"enddate", NEW.enddate,
"referredby", NEW.referredby,
"comments", NEW.comments,
"destination", NEW.destination,
"modifydate", NEW.modifydate
)),
('insert',CURRENT_TIMESTAMP);
end if;
if emp_pos="python dev" then
insert into emp(emp_sal) value (25000.00),
(JSON_OBJECT(
"dmltype", NEW.dmltype,
"title", NEW.title,
"begdate", NEW.begdate,
"enddate", NEW.enddate,
"referredby", NEW.referredby,
"comments", NEW.comments,
"destination", NEW.destination,
"modifydate", NEW.modifydate
)),
('insert',CURRENT_TIMESTAMP);
end if;
if emp_pos="full stack dev" then
insert into emp(emp_sal) value (30000.00),
(JSON_OBJECT(
"dmltype", NEW.dmltype,
"title", NEW.title,
"begdate", NEW.begdate,
"enddate", NEW.enddate,
"referredby", NEW.referredby,
"comments", NEW.comments,
"destination", NEW.destination,
"modifydate", NEW.modifydate
)),
('insert',CURRENT_TIMESTAMP);
end if;
if emp_pos="devops" then
insert into emp(emp_sal) value (35000.00),
(JSON_OBJECT(
"dmltype", NEW.dmltype,
"title", NEW.title,
"begdate", NEW.begdate,
"enddate", NEW.enddate,
"referredby", NEW.referredby,
"comments", NEW.comments,
"destination", NEW.destination,
"modifydate", NEW.modifydate
)),
('insert',CURRENT_TIMESTAMP);
end if;
end
while I tried to execute the code it presented this error
Error Code: 1054. Unknown column 'dmltype' in 'NEW' 0.015 sec
my situation is I created a emp table while adding the position of the employee in emp_pos column the trigger should fill the sal column
I want to created a log based on the changes if there is other way please do suggest the way.
[ad_2]