<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'SQL Server 2008 R2', 'sql 2005', and 'sql server 2005'</title><link>http://msmvps.com/search/SearchResults.aspx?q=app:weblogs&amp;tag=SQL+Server+2008+R2,sql+2005,sql+server+2005&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'SQL Server 2008 R2', 'sql 2005', and 'sql server 2005'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Last Execution Date Time of a Stored Procedure</title><link>/http://feedproxy.google.com/~r/SqlServerCitation/~3/YC4pOfnGtxI/last-execution-date-time-of-stored.html</link><pubDate>Sun, 11 Mar 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1807260</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;On many forums I have found a very basic yet important query - “How can I know when was my Stored Procedure last executed?” And today through this blog I will try to answer this question.&lt;/p&gt;  &lt;p&gt;Actually speaking, without explicit logging or tracing, it is not possible to get this information for each and every Stored Procedure of our Database. However, we can get this detail along with many other relevant information for the stored procedure having it’s execution plan currently &lt;strong&gt;cached &lt;/strong&gt;on the server by using - &lt;strong&gt;sys.dm_exec_procedure_stats &lt;/strong&gt;It’s a system dynamic view that returns aggregate performance statistics for cached stored procedures.&lt;/p&gt;  &lt;p&gt;The important thing to note is that this view returns one row for each cached stored procedure plan, and the lifetime of the row is as long as the stored procedure remains cached. When a stored procedure is removed from the cache, the corresponding row is eliminated from this view.&lt;/p&gt;  &lt;p&gt;So, let’s see a way, using which at least we can find out the some important facts for the cached stored procedures -&lt;/p&gt;  &lt;div id="codeSnippetWrapper" style="border-right:silver 1px solid;padding-right:4px;border-top:silver 1px solid;padding-left:4px;font-size:8pt;padding-bottom:4px;margin:20px 0px 10px;overflow:auto;border-left:silver 1px solid;width:97.5%;cursor:text;direction:ltr;line-height:12pt;padding-top:4px;border-bottom:silver 1px solid;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;max-height:200px;"&gt;   &lt;div id="codeSnippet" style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;     &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:white;text-align:left;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; DBName&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:white;text-align:left;border-bottom-style:none;"&gt;&amp;#160;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:white;text-align:left;border-bottom-style:none;"&gt;  O.name,&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;  PS.last_execution_time&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:white;text-align:left;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;  sys.dm_exec_procedure_stats PS &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:white;text-align:left;border-bottom-style:none;"&gt;&lt;span style="color:#0000ff;"&gt;INNER&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; sys.objects O &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre style="padding-right:0px;padding-left:0px;font-size:8pt;padding-bottom:0px;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;border-top-style:none;line-height:12pt;padding-top:0px;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;border-right-style:none;border-left-style:none;background-color:#f4f4f4;text-align:left;border-bottom-style:none;"&gt;  &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; O.[object_id] = PS.[object_id] &lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;P.S. &lt;/strong&gt;Please replace the &lt;strong&gt;DBName &lt;/strong&gt;with the actual name of the Database.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The above script will return the name of all the cached stored procedure of the current database with their last execution time.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For more details on this dynamics view, please refer - &lt;a href="http://msdn.microsoft.com/en-us/library/cc280701.aspx" target="_blank"&gt;sys.dm_exec_procedure_stats (Transact-SQL)&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/8332641-3824057704994708197?l=www.sql-server-citation.com" alt="" /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=yIl2AUoC8zA" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=63t7Ie-LG7Y" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=dnMXMwOfBR0" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=7Q72WNTAKBA" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?i=YC4pOfnGtxI:sjLpSQ49lOI:V_sGLiPBpWU" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=qj6IDK7rITs" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?i=YC4pOfnGtxI:sjLpSQ49lOI:KwTdNBX3Jqk" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:l6gmwiTKsz0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=l6gmwiTKsz0" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?i=YC4pOfnGtxI:sjLpSQ49lOI:gIN9vFwOqvQ" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:TzevzKxY174"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=TzevzKxY174" border="0" alt="" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/SqlServerCitation?a=YC4pOfnGtxI:sjLpSQ49lOI:nQ_hWtDbxek"&gt;&lt;img src="http://feeds.feedburner.com/~ff/SqlServerCitation?d=nQ_hWtDbxek" border="0" alt="" /&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SqlServerCitation/~4/YC4pOfnGtxI" height="1" width="1" alt="" /&gt;</description></item></channel></rss>