November 4, 2016 at 2:54 am
How do I find when was the last time :
1) I executed insert script in DB
1) I executed update script in DB
DB: sqlserver 2008 R2
November 4, 2016 at 2:59 am
Unless you have some custom monitoring in place, you don't. SQL doesn't track that information.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 4, 2016 at 6:46 am
I agree 100% with Gail. To do this accurately, you need to have monitoring in place.
However, you could look to the Dynamic Management View, sys.dm_exec_query_stats. That does have the last executed time for all the queries that are currently in cache on your system. Assuming you search this for INSERT or UPDATE (you'll have to combine it with sys.dm_exec_sql_text), you can sort of find what you're looking for. However, it is dependent on the query being in cache. If it's aged out of cache or was removed for any other reason, you won't find the information you're looking for.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 4, 2016 at 8:50 am
With the understanding that it clears out on a restart of the SQL Service, you could also look at sys.dm_db_index_usage_stats. It won't differentiate between INSERTs and UPDATEs but it will tell you when the last time either one of those happened.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 4, 2016 at 8:57 am
Jeff Moden (11/4/2016)
With the understanding that it clears out on a restart of the SQL Service, you could also look at sys.dm_db_index_usage_stats. It won't differentiate between INSERTs and UPDATEs but it will tell you when the last time either one of those happened.
And it also won't say anything about who ran the insert/update.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 4, 2016 at 12:36 pm
GilaMonster (11/4/2016)
Jeff Moden (11/4/2016)
With the understanding that it clears out on a restart of the SQL Service, you could also look at sys.dm_db_index_usage_stats. It won't differentiate between INSERTs and UPDATEs but it will tell you when the last time either one of those happened.And it also won't say anything about who ran the insert/update.
Correct. Missed the "I" in the original post.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply