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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Triggers.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-15 : 07:47:05
Neal writes "Hi,

I wonder if someone can help please?

I need to record all Delete/Insert/Updates made on all columns(fields) within a specific table and then send an email to myself when an occurrence is made.

I have very basic skills in SQL, and also need to know whether this can be achieved in one trigger.

Also, does this trigger have to be defined as a 'After/For/Instead Of' trigger?

Below is the first lines of the trigger listing both the Table and 3 of the fields within the table:

CREATE TRIGGER [tr_HCCharges Amendments] ON [dbo].[HCCharge]
FOR INSERT, UPDATE, DELETE
AS
Declare @Year nvarchar(50)
Declare @Key float(8)
Declare @Code integer

Thanks in advance,

Neal."

Thrasymachus
Constraint Violating Yak Guru

483 Posts

Posted - 2005-08-15 : 09:45:32
Do not email yourself from a trigger. It just sounds like bad news.

Use the trigger to populate a table and set up a job to scan that table new records and have the job email you.

I perfer AFTER but it all depends on what you want to do.

====================================================
Regards,
Sean Roussy

Thank you, drive through
Go to Top of Page
   

- Advertisement -