Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

finding recently run statements

Posted on 2011-02-16
5
Medium Priority
?
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 2000 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 40

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 40

Assisted Solution

by:lcohan
lcohan earned 2000 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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