I've got the following INSTEAD OF DELETE trigger, which sends an email while rolling back any Delete attempts.
ALTER TRIGGER tr_OnDel_Orders
ON ORDERS
INSTEAD OF DELETE
AS
BEGIN
SET NOCOUNT ON;
declare @b varchar(5000)
Declare @OrderID BIGINT,
SELECT @OrderID = OrderID
FROM deleted d
set @b = 'Someone attempted to delete the following order:' + CHAR(10);
set @b = @b + ' OrderID: ' + cast(@OrderID as varchar(30)) + CHAR(10);
set @b = @b + ' UserID: ' + SYSTEM_USER
RAISERROR('Cannot delete order', 16, 1)
ROLLBACK TRAN
EXEC msdb.dbo.sp_send_dbmail @recipients = 'myemail@mycompany.com',
@body = @b,
@subject = 'Attempt to Delete an order'
RETURN
END
GO
This works when I try to delete an order from the ORDERS table. However, I cannot understand why, this trigger keeps sending emails periodically with empty body. As far as I'm aware, there are no obvious attempts to delete an order. What else could cause such blank emails?