Alert when row deleted (SQL Server 2012)
-
Hello all. In SQL Server 2012, it is possible to have an email sent to a group when a row is deleted from a given table? Regards.
-
Hello all. In SQL Server 2012, it is possible to have an email sent to a group when a row is deleted from a given table? Regards.
Not having tried this, but I would imagine you can create a trigger on delete from the table that calls a stored procedure to send an e-mail. As for the syntax, you should be able to find how to create the trigger relatively easily. But, for sending e-mail, that may be dependent on your e-mail platform.
-
Hello all. In SQL Server 2012, it is possible to have an email sent to a group when a row is deleted from a given table? Regards.
I would not recommend sending an email directly from a delete trigger because you may pay a performance penalty and possibly abort your delete transaction if the email server cannot send your message. Slight change in approach would be to write a custom "logging" table where you capture the entire row from the table and store it. You can then have a separate program read through this table and send emails notifying your distribution list. The other advantage is that you have a copy of the deleted data. You can purge this data as you see fit. Just and idea. :rose::cool:
-
I would not recommend sending an email directly from a delete trigger because you may pay a performance penalty and possibly abort your delete transaction if the email server cannot send your message. Slight change in approach would be to write a custom "logging" table where you capture the entire row from the table and store it. You can then have a separate program read through this table and send emails notifying your distribution list. The other advantage is that you have a copy of the deleted data. You can purge this data as you see fit. Just and idea. :rose::cool:
Thanks to both for your pointers.