Solved

finding recently run statements

Posted on 2011-02-16
5
217 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
ID: 34910957
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
ID: 34911006
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
ID: 34935856
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
ID: 34954707
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
ID: 34985881
thanks lcohan- for your detailed query.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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