Audit updates with old and new values

Audit updates with old and new values

Medium SQL Triggers 23 views
Explanation Complexity

Problem Statement

On Employees salary update, insert into SalaryAudit(emp_id, old_salary, new_salary, changed_at).

Input Format

SQL DDL

Output Format

Trigger created

Example

Employees, SalaryAudit
Trigger created

Constraints

SalaryAudit exists

Input / Output Format

Input Format
SQL DDL
Output Format
Trigger created
Constraints
SalaryAudit exists

Examples

Input:
Employees, SalaryAudit
Output:
Trigger created

Example Solution (Public)

SQL
CREATE TRIGGER trg_salary_audit AFTER UPDATE ON Employees FOR EACH ROW INSERT INTO SalaryAudit(emp_id, old_salary, new_salary, changed_at) VALUES (OLD.emp_id, OLD.salary, NEW.salary, CURRENT_TIMESTAMP);

Official Solution Code

CREATE TRIGGER trg_salary_audit AFTER UPDATE ON Employees FOR EACH ROW INSERT INTO SalaryAudit(emp_id, old_salary, new_salary, changed_at) VALUES (OLD.emp_id, OLD.salary, NEW.salary, CURRENT_TIMESTAMP);
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.