Trigger for update

Abhisek
Posted by Abhisek under Sql Server category on | Views : 2017
CREATE TRIGGER tu1 ON Student FOR UPDATE AS 'Record updated successfully''

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

UPDATE Student set Name='Abhisek Panda' whwre roll=108

The output will be the following:

Record inserted successfully
1 row(s) affected

Let us see another trigger,
CREATE TRIGGER tu2 ON Student FOR UPDATE AS select*from deleted select*from inserted


Deleted and inserted are logical tables and are structurally similar to the table on which the trigger is defined. That is, the table on which the user action is attempted, and hold the old values and new 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 which is deleted and the data which is updated
UPDATE Student set Name='Abhisek Panda' whwre roll=108

Name Roll
Abhisek 108

Name Roll
Abhisek Panda 108
1 row(s) affected

Comments or Responses

Posted by: Raja on: 11/27/2009 Level:Starter | Status: [Member]
Thank you for giving example of Insert, Update and Delete triggers.

Its very informative.

Keep it up Abhisek!

Login to post response