Identify the action that is deleting all rows in a table

前端 未结 2 530
无人及你
无人及你 2021-01-28 21:13

There is SQL Server 2012 database that is used by three different applications. In that database there is a table that contains ~500k rows and for some mysterious reason this ta

2条回答
  •  礼貌的吻别
    2021-01-28 22:00

    This is a possibility that may help you. It creates a trigger on Table1 that sends an email when a process DELETEs more than 100 records. I'd modify the message to include some useful data like:

    1. Process ID (@@SPID)
    2. Host (HOST_NAME())
    3. Name of app (APP_NAME())
    4. And possibly the entire query

    CREATE TRIGGER Table1MassDeleteTrigger
    ON dbo.Activities
    FOR DELETE 
    AS
        DECLARE @DeleteCount INT = (SELECT COUNT(*) FROM deleted)
    
        IF(@DeleteCount > 100)
            EXEC msdb.dbo.sp_send_dbmail
            @profile_name = 'MailProfileName',
            @recipients = 'admin@yourcompany.com',
            @body = 'Something is deleting all your data!',
            @subject = 'Oops!';
    

提交回复
热议问题