Trigger

  • I am having a table called sonic. whenever any

    changes insert/delete/update done in the table i

    need to send a email alert . please some body give me sample code.

  • Assuming you've already installed dbmail on your instance then the code should look like:

    SET

    ANSI_NULLS ON

    GO

    SET

    QUOTED_IDENTIFIER ON

    GO

    CREATE

    TRIGGER schema_name.trigger_name

    ON schema_name.table_name

    AFTER

    <INSERT,DELETE,UPDATE>

    AS

    BEGIN

    declare @var bigint

    set @var=0

    select @var=count(*) from inserted,deleted

    if @var>0 then

    EXEC msdb.dbo.sp_send_dbmail @recipients='you@yourdomain.com',

    @subject

    = 'Sample: Data values modified',

    @body

    = @bodymsg,

    @body_format

    = 'HTML'

    END

    GO

    I would not do this if I'd have bulk inserts/updates/deletes.

    Good luck.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply