Forum Discussion
RuthlessRoth
Aug 07, 2024Copper Contributor
Trigger to send email if a table has had a INSERT, UPDATE OR DELETE
We need a trigger to be sent out if ProcessSchedule has had an INERT, UPDATE or DELETE We don't need details just a heads up type of email. The send email part is easy. EXEC msdb.dbo.sp_send...
rodgerkong
Aug 08, 2024Iron Contributor
use SQL Script below to create a trigger:
CREATE TRIGGER SendNotifyMail
ON ProcessSchedule
AFTER INSERT, UPDATE, DELETE
AS
EXEC msdb.dbo.sp_send_dbmail profile_name = 'SQLMail'
,@recipients = 'email address removed for privacy reasons'
,@body = 'Press Schedule Changed'
,@subject = 'Press Schedule Changed' ;
GO
And check out document https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-ver16 for more information
- RuthlessRothAug 12, 2024Copper ContributorThanks. The trigger didn't work for this application. The issue is the table has a lot of Inserts, Updates and Deletes that do not relate to specific records. I resorted to a SQL Job to check every 30 minutes if a specific record or records have been modified within the past 30 minutes based on the data put into a UpdateDateTim field that is used when a record has been changed.
- rodgerkongAug 13, 2024Iron Contributor
I used to add a rowversion column in table to identify which row had been modified. Its value will be auto increased with any update of the row. Check document https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver16.
- RuthlessRothAug 13, 2024Copper ContributorGood Idea. Downside I do not have control over the table structure. I am working with a application that I did not design. When updates are sent out to the software it checks table structure and resets it to their design.