How to determine the last time records were inserted, updated or deleted for a table?

Possible duplicate:
How to execute a search function for sql database and how to get the time when the information from the table has been edited?

How to determine the last time records were inserted, updated or deleted for a table?

someone told me

select * from sys.dm_db_index_usage_stats where database_id = db_id( 'readpasttest' ) 

But I do not know how to use it. I have a database table on asp.net where I add the following data:

 edit-1.Name : Jax edit-2.Age : 24 edit-3.Code : 12515 

therefore, when users edit something, we can say that the Jax name will be like this:

 edit-1.Name : newName - This was edited last time : the time/day ! 

Please, help,

+4
source share
1 answer

For changes, you can add a datetime column to a table called "LastModified" or something like that and write the current date / time to it every time you record.

Alternatively, if you need to know when a record was deleted, you can write a trigger that captures inserts / updates / deletes in the corresponding table and writes the timestamp value to another table along with identifying information about this record.

The best way is to implement “soft deletions” when the record is marked with some status (for example, the “IsDeleted” column), which can be turned over and subsequently ignored by other code in the application when reading from the table.

+1
source

Source: https://habr.com/ru/post/1399082/


All Articles