Below is scripts to create trigger in mssql :
Trigger insert
CREATE TRIGGER employee_aft_ins ON employee AFTER INSERT AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM INSERTEDTrigger Update
CREATE TRIGGER employee_aft_upd ON employee AFTER UPDATE AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM DELETEDTrigger Delete
CREATE TRIGGER employee_aft_del ON employee AFTER DELETE AS INSERT INTO employee_log SELECT ID,FirstName,LastName FROM DELETEDNotes
Replace tables and fields name with your own
employee is the original table, while employee_log is table to save log history of original table
No comments:
Post a Comment