Prevent salary decrease beyond 20%
SQL
Hard
0 views
Problem Description
Before updating Employees.salary, block the update if the new salary is less than 80% of the old salary.
Output Format
Trigger created
Constraints
MySQL-style OLD/NEW with SIGNAL
Official Solution
CREATE TRIGGER trg_salary_cut BEFORE UPDATE ON Employees FOR EACH ROW BEGIN IF NEW.salary < OLD.salary * 0.80 THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='Salary cut too large'; END IF; END;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!