I have a trigger that monitors changes to database objects. Below is the code when I created the trigger:
CREATE TRIGGER db_trg_ObjectChanges
ON DATABASE
FOR ALTER_PROCEDURE, DROP_PROCEDURE,
ALTER_INDEX, DROP_INDEX,
ALTER_TABLE, DROP_TABLE, ALTER_TRIGGER, DROP_TRIGGER,
ALTER_VIEW, DROP_VIEW, ALTER_SCHEMA, DROP_SCHEMA,
ALTER_ROLE, DROP_ROLE, ALTER_USER, DROP_USER
AS
SET NOCOUNT ON
INSERT dbo.ChangeAttempt
(EventData, DBUser)
VALUES (EVENTDATA(), USER)
GO
The table dbo.ChangeAttempt has the following structure:
Column Data Type Constraints
------ --------- -----------
EventData xml NOT NULL
AttemptDate datetime NOT NULL DEFAULT GETDATE()
DBUser char(50) NOT NULL
I'd like to be alerted if any entries are found in the table dbo.ChangeAttempt for the current date. The email will just tell me that entries were found in dbo.ChangeAttempt on the current date. I am using blat or bmail in sending most of my monitoring alerts. I do select statements and output it to text file and then email the output to me.
My question is: How do I programatically send alert if there has been entries found in the dbo.ChangeAttemptfor the current date(an indication of database change attempt)?