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 table gets emptied every now and then. I think this is possibly caused by:
- A delete query without a where clause
- A delete query in a loop gone wild
I am trying to locate the cause of this issue by reviewing code but no joy. I need an alternate strategy. I think I can use triggers to detect what/why all rows get deleted but I am not sure how to go about this. So:
- Can I use triggers to check if a query is attempting to delete all rows?
- Can I use triggers to log the problematic query and the application that issues that query?
- Can I use triggers to log such actions into a text file/database table/email?
- Is there a better way?