This blog discusses the steps to determine the user responsible for truncating and removing data from tables on MSSQL server, and identify the entity responsible.
For example: When was the table truncated, and when was the data removed from the table? Who truncated the table and removed data from table?
This is to see if someone deleted the data on purpose or by accident, so we can track down the individual and take preventative action. We receive few requests from customers looking for this information. When we know the exact time of data purge operation then we can easily recover the data with stop at clause during log backup operation.
The following sections describe four key principles for GitOps:
Between 5 p.m. and 7 p.m. on January 5, 2020, the “dump truncate” table was truncated and the data from the “dump delete” table was removed from the “truncate test” DB. The probable questions that need to be addressed include:
NOTE: We performed these steps by creating a new copy of the DB.
Restore 2nd Jan Sunday full backup with standby mode.
Restore 5th Jan diff backup with standby mode
Restore log backup with standby mode. Check the table count after each log restore to see which log backup holds the truncate and delete operation logs.
When we restored the log backup from 6 PM, the “dump truncate” table was empty, and entries from the “dump delete” table were missing. As a result, it denotes:
Between 5:45 PM and 6 PM, the “dump truncate” table was truncated, and data from the “dump delete” table was wiped at the same time.
You need to run the following restore commands:
Identify details of truncate and delete operations using log backup:
Step 1: Collect transaction IDs for all truncate and delete operations that occurred between 5:45 and 6 p.m.
Query:
We discovered that two operations, delete and truncate, were executed at 5:50 PM, and that these operations were performed by login RP Dev.
Step 2:Find the table names that are associated to the transaction id.
To get information on the delete operation, follow the steps below:
I) Determine the delete operation’s object ID and partition ID.
From this output, we can deduce the following information: Description and Transaction Name columns: Delete operation was performed
II) Locate a table that contains the object ID and partition ID.
Query:
Now we can deduce that data from “dump delete” was removed by RP DEV user at 5:50 PM under the transaction ID ‘0000:00016a96’ and that a total of 7 rows were deleted.
To get information on the truncate operation, follow the steps below:
I) Determine the Truncate operation’s object ID and partition ID.
Output:
Now we can deduce that data from “dump delete” was removed by RP DEV user at 5:50 PM under the transaction ID ‘0000:00016a96’ and that a total of 7 rows were deleted.
To get information on the truncate operation, follow the steps below:
I) Determine the Truncate operation’s object ID and partition ID.
Query:
Output
The output of the truncate operation differs slightly from that of the delete operation.
Partition ID column: It is not displaying the correct partition ID. You can find this information in the description column. Partition ID is highlighted. Partition IDs are 72057594043564032 and 72057594043629568
Lock Description: Always SCH_M_OBJECT row in Lock Description shows the correct Object ID. Object ID is: 885578193
Locate a table that contains the object ID and partition ID
Query:
Output
We can now establish that data from “dump truncate” was truncated at 5:50 PM by RP_DEV user under the transaction ID'0000:00016a95'.
It is useful to know who performed truncate and delete operation on data to avoid this from happening again when auditing is not already enabled. In case of delete operation, business will have idea how many rows are removed. To have exact time of recovery will be very helpful to recover the data. Further third-party tools like ApexSQL Log and ApexSQL Recover can also be used to recover the data. Refer this link to have knowledge about these tools:
Let our experts guide you on your next gen data platform journey.
Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.