Trigger: Audit Salary Changes
Create a trigger that, after a salary update on Employees, inserts a row into Salary_Audit with the employee id, old salary, new salary and the change time, only when the salary actually changed.
Table schema
Employees(id INT PRIMARY KEY, name VARCHAR(50), salary INT)
Salary_Audit(emp_id INT, old_salary INT, new_salary INT, changed_at TIMESTAMP)Sample data
Employee (1, 'Asha', 50000)
Statement: UPDATE Employees SET salary = 55000 WHERE id = 1;
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.