Simple Trigger for any Update and Delete

Today,  I am going to show you the simplest example of trigger for looking any modification happens in your Table. first of all definition of trigger :

Trigger

Trigger is a block of code, that perform operations like. Insert, Update or delete .

I have Live table EMPLOYEE.

Someone told me to create log for employee table quickly.

First, I created log table EMPlog by this simple command.

---Select Cast(null as datetime) [LogDate], * into EMPLOG from EMPLOYEE where 1=0

This creates our log table with logdate column.

Secondly, I have to put trigger on EMPLOYEE table .with the simplest command for trigger.

---CREATE TRIGGER EMPTRIG ON EMPLOYEE FOR DELETE, UPDATE
AS
INSERT INTO EMPLOG SELECT GETDATE(),* FROM DELETED

by running this two simplest code we can create trigger for log of any deletion or modification captures 

Ebook Download
View all
SQL Jobs
Read by 0 people
Download Now!
Learn
View all