Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

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.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.