Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view the history of inserts to a table?

Tags:

sql-server

Is there a way to see the history or any other information of insertions into a specific table of an SQL Server database?

like image 670
mkamowski Avatar asked Jan 23 '23 19:01

mkamowski


2 Answers

Unless you are recording this information somewhere using a trigger, you would need some way of looking at the information in the transaction log. There are commercial tools like Lumigent for this.

like image 149
David M Avatar answered Jan 31 '23 21:01

David M


You could use a trigger

Create a trigger on the table watching for inserts, updates, and deletes). The trigger would insert into another table (a history table).

This adds extra overhead, though, so I wouldn't do this on a really heavily updated table.

Look at this page for an example of how this is done.

This page has some code that generates the audit trail code for you.

Here is another SOF question about doing this using triggers.

like image 39
Gabriel McAdams Avatar answered Jan 31 '23 21:01

Gabriel McAdams