This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing few steps to find out the transactions history for drop commands which executed in SQL Server.
There are many features for auditing and check the logging in SQL Server, but you can also directly read the transaction log and can get the necessary details.
Please check the below full demonstration of this:
Create a sample database and use it:
1 2 3 4 |
CREATE DATABASE Drop_Test GO USE Drop_Test GO |
1 2 |
CREATE TABLE tbl_Test (ID INT) GO |
1 2 3 4 |
SELECT OBJECT_ID ('tbl_Test') GO --tbl_Test object id: 581577110 |
1 2 |
DROP TABLE tbl_Test GO |
Using below query, you can find only transaction id and username who dropped the objects. Later, you can use a transaction to know which object has been dropped.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT [Transaction Id], [Begin Time], SUSER_SNAME ([Transaction SID]) AS [User] FROM fn_dblog (NULL, NULL) WHERE [Transaction Name] = 'DROPOBJ' GO -- The Result: /* Transaction Id Begin Time User -------------- ------------------------ --------- 0000:00000335 2017/04/25 17:53:41:187 Anvesh */ |
Use above transaction id and see the details of dropped object.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT [Transaction Id], [Begin Time], SUSER_SNAME ([Transaction SID]) AS [User] FROM fn_dblog (NULL, NULL) WHERE [Transaction Name] = 'DROPOBJ' GO -- The Result: /* Transaction Id Begin Time User -------------- ------------------------ --------- 0000:00000335 2017/04/25 17:53:41:187 Anvesh */ |
Leave a Reply