Sql-server – Checking when a row was inserted into a table on SQL Server

sql server

Is it possible to check when a specific row was inserted into a specific table in SQL Server ?
The table has an index if this any help.

And I need to do this for an existing table where the row has already being inserted.


Best Answer

To achieve this retrospectively you could do so by inspecting the contents of the transaction log to identify when the insert occurred, of course you need to have access to the relevant transaction log that contains the details.

Here is a walkthrough of how you would inspect the transaction log to locate a table drop event but the process you would follow is mostly the same.

If auditing of this level is actually something that's required then your best bet is to build it into your overall solution, whether through the use of DML Triggers, CDC or Change Tracking or a customised solution.