mysql - Why doesnt this SQL trigger work? Selecting Sum and updating -
USE 'DEPT`; DELIMITER $$ create = DEFINER = `Route` @ localhost` trigger 'R3`; Announce the pay difference after updating on' Employee 'for everyday; SET pay = (Select the SUM (pay) from the employee salary, where employee employee, DO = new employee. Employee); Updated department set Total_sal = salary Where Dno = NEW.Dno; END The salary is zero and it is throwing an error because it can not be.
The error was due to the conflict in the column name with the variable name salary .
It will always be a good practice to use the relevant name, but the name of the column will not be named. And you need to make some logical changes in updating the total salary in the department table.
You are only updating the total salary of the department while adding new employees.
You should also change which will be the same from the department which has been transferred to this employee.
The trigger should work after a change:
drop trigger if present then `R3`; DELIMITER $$ after triggering the trigger `R3` for updating on 'Employee' for everyday; declare old_dept_total_salary int; Announce new_dept_total_salary int; - If EMP has been taken to a new department, then - the credit card of the former department is affected by the employee choosing the old SIM (salary) where Employee DipTown = Old Depoteno Group employee employee. - Update it Update department set Total_sal = old_dept_total_salary WHERE deptno = OLD.deptno; - If the EMP has been taken to a new department, then - the new notification also affects the new_pagat_roll_saulari from the employee who gets the SUM (salary) to the employee, where Employee Diptyen = Employee Employee Deptto of the Nudipatanno Group; - Update it Update department set Total_sal = new_dept_total_salary WHERE deptno = NEW.deptno; End; $$ delimiter; After you turn on employee to correct total_sal, trigger the and after triggering trigger Demo @ Div>
Comments
Post a Comment