Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Trigger Syntax

Author  Topic 

vdavid70
Yak Posting Veteran

67 Posts

Posted - 2005-08-30 : 06:17:40
I am trying to write a trigger that will send a message to the administrator when any delete or update statement is made to any table within the database.
I will like the message to include the name of the user that deleted the record as well as the tables they deleted or updated.

Could someone please help with the syntax? Thanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-08-30 : 07:48:26
It's better to avoid having a trigger send a message, because if there is any overhead or delay in completing the send it could negatively affect SQL Server performance (to the point of locking up the server).

Instead, have the trigger insert the relevant information into a table, then create a scheduled job that runs periodically to query that table and send the results to the admin. That way no other operations are affected, and you can consolidate as much data as you like before sending it. I'll tell you know that no admin will want to get an email every minute or even 10 minutes that someone deleted something, they'll very quickly ignore all such messages.

Also, if this is meant to keep track of people who are deleting or updating tables they should not be, it's easier to simply DENY them the permissions to do that.
Go to Top of Page
   

- Advertisement -