12

Is it possible to view delete statements that have recently occurred in the Transaction Log?

Philᵀᴹ
  • 31,952
  • 10
  • 86
  • 108
Neil Knight
  • 677
  • 3
  • 12
  • 21

2 Answers2

12

you wont find the exact scripts that were executed on sql.(in the transaction log)

A transaction log is a file that contains information regarding every change that has been made to the database. This includes data modifications (transactions), database modifications, and backup/restore events.

The primary purpose the transaction log is to provide a method to be able to restore a database to a point-in-time when necessary. This can include rolling back transactions to a certain time, or to roll forward transactions from a full backup restoration.

to know more about Transaction log http://www.sqlservercentral.com/articles/Design+and+Theory/63350/

here is a script to show you recent ran delete queries

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
where dest.TEXT like '%Delete%from%'
ORDER BY deqs.last_execution_time DESC
AmmarR
  • 2,826
  • 3
  • 28
  • 33
11

You can view the individual rows that were deleted by looking for LOP_DELETE_ROWS operations still in the log:

select * from fn_dblog(NULL, NULL) 
where Operation = 'LOP_DELETE_ROWS'

If the log was recycled (in simple recovery model) or truncated by backup (in full or bulk recovery model) then you will only be able to see the log operations still available in the log.

Understanding the log operations is quite complex, you need to be aware of things like undo or compensating operations to make sense of some log patterns you can encounter, but straight forward committed DELETEs are fairly easy to comprehend.

Remus Rusanu
  • 52,054
  • 4
  • 96
  • 172