Trigger for delete

Abhisek
Posted by Abhisek under Sql Server category on | Views : 1542
CREATE TRIGGER td1 ON Student FOR DELETE AS Print 'Record inserted successfully'

It will create a trigger for delete operation in the student table. The database and table must exists and the trigger should be unique.

DELETE FROM Student WHERE Roll=107

The output will be the following:

Record inserted successfully
1 row(s) affected

Let us see another trigger,
CREATE TRIGGER td2 ON Student FOR DELETE AS select*from deleted


Deleted is a logical table and the structure is similar to the table on which the trigger is defined. That is, the table on which the user action is attempted, and the old values of the rows that may be changed by the user action.

Now fire this trigger, and see the output. It will display the data we just delete.
DELETE FROM Student WHERE Roll=107

Name Roll
Abinash 107
1 row(s) affected

Comments or Responses

Login to post response