Solved

finding recently run statements

Posted on 2011-02-16
5
214 Views
Last Modified: 2012-05-11
i had run some recent statement from query window.. but i am trying to track exact parameters i sent.. but i could not see it from the below query..

there are a bunch of statements even from a week before- so i know memory is not the issue.. what am i missing.. isn't every select and execute statement cached?

thanks
SELECT  text,last_execution_time
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
WHERE last_execution_time between 
'2011-02-16 13:00:00.000' and '2011-02-16 14:45:00.000'
and text like '%sp_send_dbmail%'
ORDER BY qs.last_execution_time DESC

Open in new window

0
Comment
Question by:anushahanna
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
Comment Utility
I believe not all statements will stay in cache forever even if lets say you have infinite memory.
If you look in particular for your sent mail please run following

select * from msdb..sysmail_unsentitems

select top 100 * from msdb..sysmail_sentitems order by sent_date desc
0
 
LVL 39

Expert Comment

by:lcohan
Comment Utility
Or just run this without date limit:

SELECT  top 100 text,last_execution_time
      FROM sys.dm_exec_query_stats qs
            CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
            CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
      WHERE text like '%sp_send_dbmail%'
      ORDER BY qs.last_execution_time DESC
0
 
LVL 6

Author Comment

by:anushahanna
Comment Utility
lcohan, still could not get it.. even though there is entry from before when these were written. do this come under your category you mentioned "I believe not all statements will stay in cache"- if so, what might they be?
0
 
LVL 39

Assisted Solution

by:lcohan
lcohan earned 500 total points
Comment Utility
Sorry I created more confusion than helped. Here, please run the query below and have a look at the creation_date vs. last_execution_time. They will be different for objects planned and stored in cache at the creation_time and last executed on last_execution_time - this should be pretty strait forward.
The objects you see with old creation_time were planned/stored in cache since and what I'm trying to say is that not ALL objects will stay in cache forever or for for the same duration. You could see the query plan if you click the link on the last column.

SELECT top 100 text,creation_time,last_execution_time,query_plan
    FROM sys.dm_exec_query_stats qs
       CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
       CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp

Now, if you look in particular for "sp_send_dbmail" queries then you could find all sent/unsent mail info in the two: msdb..sysmail_unsentitems and msdb..sysmail_sentitems
0
 
LVL 6

Author Comment

by:anushahanna
Comment Utility
thanks lcohan- for your detailed query.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now