Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger - How to tell operation type

Status
Not open for further replies.

tomjscribe

Programmer
Dec 21, 2000
4
US
Writing a generic trigger for all operations (Update, Insert, Delete).
How can I tell what type of operation against the table has occurred.
I want one, generic I/U/D trigger that needs slightly different behavior for each operation.
Basically, I am writing an 'audit trail' trigger and need to record the operation type in an audit table.
For example:

IF @opertype = "Delete"
BEGIN
INSERT AuditTable (operation_type) VALUES ("D")
END
ELSE
IF @opertype = "Update"
BEGIN
INSERT AuditTable (operation_type) VALUES ("U")
END
ELSE
IF @opertype = "Insert"
BEGIN
INSERT AuditTable (operation_type) VALUES ("I")
END

Thanks!

 
If the deleted rowcount > 0 and inserted rowcount = 0 then it's a delete.

If the inserted rowcount > 0 and the deleted rowcount = 0 then it's an insert.

If the deleted rowcount > 0 and the inserted rowcount > 0 then it's an update.

Tom Davis
tdavis@sark.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top