TSQL -> Example of DELETE trigger


This trigger saves copy of deleted record to DELETE Archive table:

CREATE TRIGGER EmpFacts_del_trig ON dbo.EmployeeFacts
  FOR DELETE
AS
BEGIN

/* DeleteArchive table stores deleted records from table EmployeeFacts */

  INSERT INTO DeleteArchive ([FactNo],[EmpNo],[fact],
   [createdate],[edit_status],[lastupdate],[UPDBY],[DTime])
  SELECT [FactNo], [EmpNo], [fact], [createdate],
   [edit_status],[lastupdate],[UPDBY], GETDATE()
  FROM deleted;

END


sqlexamples.info