Trigger insert, update, and delete
CREATE TRIGGER YourTrigger ON YourTableAFTER INSERT,UPDATE,DELETEASIF EXISTS (SELECT * FROM INSERTED)BEGINIF EXISTS (SELECT * FROM DELETED)BEGIN--UPDATEENDELSEBEGIN--INSERTEND--handle insert or update dataENDELSE IF EXISTS(SELECT * FROM DELETED)BEGIN--DELETE--handle delete data, insert into both the history and the log tablesEND