Complete the code to create an AFTER INSERT trigger on the employees table.
CREATE TRIGGER trg_after_insert ON employees AFTER [1] AS BEGIN PRINT 'Employee inserted'; END;
The trigger is set to run after an INSERT operation on the employees table.
Complete the code to reference the inserted row in an AFTER INSERT trigger.
CREATE TRIGGER trg_after_insert_salary ON employees
AFTER INSERT
AS
BEGIN
SELECT salary FROM [1];
END;In AFTER INSERT triggers, the inserted table holds the new rows.
Fix the error in the AFTER DELETE trigger code to correctly reference the deleted rows.
CREATE TRIGGER trg_after_delete ON employees
AFTER DELETE
AS
BEGIN
SELECT * FROM [1];
END;The deleted table holds the rows that were removed in a DELETE trigger.
Fill both blanks to create an AFTER UPDATE trigger that logs old and new salaries.
CREATE TRIGGER trg_after_update_salary ON employees AFTER UPDATE AS BEGIN INSERT INTO salary_log (old_salary, new_salary) SELECT [1].salary, [2].salary FROM deleted [1], inserted [2] WHERE [1].employee_id = [2].employee_id; END;
Aliases d and i are used for deleted and inserted tables to compare old and new values.
Fill all three blanks to create an AFTER INSERT trigger that updates a summary table with the new employee count.
CREATE TRIGGER trg_after_insert_count ON employees AFTER INSERT AS BEGIN UPDATE employee_summary SET total_employees = total_employees + [1] WHERE department_id = (SELECT [2] FROM inserted LIMIT 1); PRINT '[3] employees added'; END;
The trigger adds 1 to the count, uses department_id from inserted, and prints a message.