<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblogcasts.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Jason Massie's SQL blog</title><subtitle type="html" /><id>http://sqlblogcasts.com/blogs/jasonmassie/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblogcasts.com/blogs/jasonmassie/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2007-11-25T00:54:00Z</updated><entry><title>SQL 2008 CTP6</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/19/sql-2008-ctp6.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/19/sql-2008-ctp6.aspx</id><published>2008-02-20T01:09:00Z</published><updated>2008-02-20T01:09:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://download.microsoft.com/download/3/1/5/315b8683-3765-4426-96ec-179360abb82f/Download_Instructions_ENU.htm"&gt;http://download.microsoft.com/download/3/1/5/315b8683-3765-4426-96ec-179360abb82f/Download_Instructions_ENU.htm&lt;/a&gt;&lt;/p&gt;&lt;p&gt;or &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=749BD760-F404-4D45-9AC0-D7F1B3ED1053&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=749BD760-F404-4D45-9AC0-D7F1B3ED1053&amp;amp;displaylang=en&amp;nbsp;&lt;/a&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Powershell provider&lt;/li&gt;&lt;li&gt;Filtered indexes and stats!!!!!!!&lt;/li&gt;&lt;li&gt;Data and index compression&lt;/li&gt;&lt;li&gt;Lots of other stuff.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=7537" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="Indexes" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Indexes/default.aspx" /><category term="SQL Server 2008" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQL+Server+2008/default.aspx" /><category term="CTP6" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/CTP6/default.aspx" /></entry><entry><title>SQL Server LinkedIn group</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/18/sql-server-linkedin-group.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/18/sql-server-linkedin-group.aspx</id><published>2008-02-18T18:38:00Z</published><updated>2008-02-18T18:38:00Z</updated><content type="html">
&lt;p&gt;I have created a LinkedIn SQL Server group. &lt;a href="http://www.linkedin.com/e/gis/54395/4D730B42042F"&gt;Join up&lt;/a&gt;.&lt;/p&gt;
 
&lt;p align="center"&gt;&lt;a href="http://www.linkedin.com/e/gis/54395/4D730B42042F"&gt;&lt;img src="http://statisticsio.com/Portals/0/linkedin.jpg" alt="SQL Server Professionals" height="50" width="100"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=7466" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="networking" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/networking/default.aspx" /></entry><entry><title>Creating a custom data collection in SQL Server 2008</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/15/creating-a-custom-data-collection-in-sql-server-2008.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/15/creating-a-custom-data-collection-in-sql-server-2008.aspx</id><published>2008-02-15T06:44:00Z</published><updated>2008-02-15T06:44:00Z</updated><content type="html">&lt;p&gt;In the &lt;a href="http://statisticsio.com/Home/tabid/36/articleType/ArticleView/articleId/56/SQL-Server-2008-data-collections-in-5-minutes.aspx" target="_blank"&gt;first post&lt;/a&gt;, we took a quick look at how data collection works. In this post, we will see how to create custom data collection. &lt;/p&gt;  &lt;p&gt;To create a custom collection, you must use the stored procedures. In Bill Ramos's web cast, he hints it may stay like this i.e. NO GUI. I tend to doubt it because Microsoft built their empire making hard stuff easy.&lt;/p&gt;  &lt;p&gt;In this example, we will look at collecting 3 key indicators of a CPU bottleneck. These items are actually included in the "server activity" system data collection. However, it cannot be modified and it collects everything under the kitchen sink. Multiply that times 20 or 100 servers and you are looking at some huge storage requirements. I think smaller data collections like this will be common.&lt;/p&gt;  &lt;p&gt;Let's get to business...&lt;/p&gt;  &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;use&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; msdb&lt;span style="color:gray;"&gt;; &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;span style="font-size:10pt;color:green;font-family:'Courier New';"&gt;--Let's create the collection set &lt;/span&gt;    &lt;/p&gt;       &lt;p&gt;&amp;nbsp;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_set_id_1 &lt;span style="color:blue;"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_set_uid_2 &lt;span style="color:blue;"&gt;uniqueidentifier &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;EXEC&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; [dbo]&lt;span style="color:gray;"&gt;.&lt;/span&gt;[sp_syscollector_create_collection_set] &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@name&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;'CPU indicators'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_mode&lt;span style="color:gray;"&gt;=&lt;/span&gt;0&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Let's start in cached mode. &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@description&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;'Collects CPU KPIs from perfmon and DMVs'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@target&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;''&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Undocumented &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@logging_level&lt;span style="color:gray;"&gt;=&lt;/span&gt;0&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--0 through 2 are valid &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@days_until_expiration&lt;span style="color:gray;"&gt;=&lt;/span&gt;5&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Let's just keep data 5 days. We will rollup for reporting. &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@proxy_name&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;''&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Use if you want it to run under something other than the SQL Agent svc account. &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@schedule_name&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;'CollectorSchedule_Every_5min'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Built in schedule &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_set_id&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_set_id_1 &lt;span style="color:blue;"&gt;OUTPUT&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;                         &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_set_uid&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_set_uid_2 &lt;span style="color:blue;"&gt;OUTPUT &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_set_id_1&lt;span style="color:gray;"&gt;,&lt;/span&gt; @collection_set_uid_2 &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;              &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&amp;nbsp;&lt;span style="font-size:10pt;color:green;font-family:'Courier New';"&gt;--Let's get the needed perfmon counters &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collector_type_uid_7 &lt;span style="color:blue;"&gt;uniqueidentifier &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collector_type_uid_7 &lt;span style="color:gray;"&gt;=&lt;/span&gt; collector_type_uid &lt;span style="color:blue;"&gt;From&lt;/span&gt; [dbo]&lt;span style="color:gray;"&gt;.&lt;/span&gt;[syscollector_collector_types] &lt;span style="color:blue;"&gt;Where&lt;/span&gt; &lt;span style="color:blue;"&gt;name&lt;/span&gt; &lt;span style="color:gray;"&gt;=&lt;/span&gt; N&lt;span style="color:red;"&gt;'Performance Counters Collector Type'&lt;/span&gt;&lt;span style="color:gray;"&gt;; &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;        &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_item_id_8 &lt;span style="color:blue;"&gt;int &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;EXEC&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; [dbo]&lt;span style="color:gray;"&gt;.&lt;/span&gt;[sp_syscollector_create_collection_item] &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@name&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;'Perfmon CPU counters'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@parameters&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;' &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;PerformanceCountersCollector&amp;gt; &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;         &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;PerformanceCounters Objects="SYSTEM" Counters="Processor Queue Length" Instances="*" /&amp;gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;PerformanceCounters Objects="Processor" Counters="% Processor Time" Instances="*" /&amp;gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;/PerformanceCountersCollector&amp;gt;'&lt;/span&gt;&lt;span style="font-size:10pt;color:gray;font-family:'Courier New';"&gt;,&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_item_id&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_item_id_8 &lt;span style="color:blue;"&gt;OUTPUT&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@frequency&lt;span style="color:gray;"&gt;=&lt;/span&gt;5&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_set_id&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_set_id_1&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Output from sp_syscollector_create_collection_set &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collector_type_uid&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collector_type_uid_7 &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;         &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_item_id_8 &lt;/span&gt;    &lt;/p&gt;            &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp; &lt;br&gt;&lt;span style="font-size:10pt;color:green;font-family:'Courier New';"&gt;--Let's get the DMV data&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collector_type_uid_3 &lt;span style="color:blue;"&gt;uniqueidentifier &lt;/span&gt;         &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collector_type_uid_3 &lt;span style="color:gray;"&gt;=&lt;/span&gt; collector_type_uid &lt;span style="color:blue;"&gt;From&lt;/span&gt; [dbo]&lt;span style="color:gray;"&gt;.&lt;/span&gt;[syscollector_collector_types] &lt;span style="color:blue;"&gt;Where&lt;/span&gt; &lt;span style="color:blue;"&gt;name&lt;/span&gt; &lt;span style="color:gray;"&gt;=&lt;/span&gt; N&lt;span style="color:red;"&gt;'Generic T-SQL Query Collector Type'&lt;/span&gt;&lt;span style="color:gray;"&gt;; &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Declare&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_item_id_4 &lt;span style="color:blue;"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;EXEC&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; [dbo]&lt;span style="color:gray;"&gt;.&lt;/span&gt;[sp_syscollector_create_collection_item] &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;&amp;nbsp;  &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@name&lt;span style="color:gray;"&gt;=&lt;/span&gt;N&lt;span style="color:red;"&gt;'CPU pressure check'&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@parameters&lt;span style="color:gray;"&gt;= &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;N&lt;span style="color:red;"&gt;'&amp;lt;TSQLQueryCollector&amp;gt; &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;Query&amp;gt; &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;             &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;Value&amp;gt;select SUM(runnable_tasks_count) from sys.dm_os_schedulers where scheduler_id &amp;gt;2 &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;/Value&amp;gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;OutputTable&amp;gt;CPU_Pressure_OS_Schedulers&amp;lt;/OutputTable&amp;gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;/Query&amp;gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;Databases UseSystemDatabases="true" UseUserDatabases="true" /&amp;gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:red;font-family:'Courier New';"&gt;&amp;lt;/TSQLQueryCollector&amp;gt;'&lt;/span&gt;&lt;span style="font-size:10pt;color:gray;font-family:'Courier New';"&gt;,&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_item_id&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_item_id_4 &lt;span style="color:blue;"&gt;OUTPUT&lt;/span&gt;&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@frequency&lt;span style="color:gray;"&gt;=&lt;/span&gt;5&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collection_set_id&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collection_set_id_1&lt;span style="color:gray;"&gt;,&lt;/span&gt; &lt;span style="color:green;"&gt;--Output from sp_syscollector_create_collection_set &lt;/span&gt;      &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@collector_type_uid&lt;span style="color:gray;"&gt;=&lt;/span&gt;@collector_type_uid_3 &lt;/span&gt;    &lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;         &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;Select&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; @collection_item_id_4 &lt;/span&gt;    &lt;/p&gt;          &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;br&gt;&lt;span style="font-size:10pt;color:green;font-family:'Courier New';"&gt;--Let's start the collection &lt;/span&gt;    &lt;/p&gt;     &lt;p class="MsoNormal" style="margin:0in 0in 0pt;line-height:normal;"&gt;&amp;nbsp;&lt;span style="font-size:10pt;color:blue;font-family:'Courier New';"&gt;exec&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; sp_syscollector_start_collection_set @collection_set_id &lt;span style="color:gray;"&gt;=&lt;/span&gt; @collection_set_id_1 &lt;span style="color:green;"&gt;--Output from sp_syscollector_create_collection_set &lt;/span&gt;      &lt;p&gt;&amp;nbsp;&lt;/p&gt;   &lt;/span&gt;&lt;/p&gt;           &lt;p&gt;&amp;nbsp;&lt;font face="Calibri"&gt;We can now see that the collection has been created in SSMS. This is what it looks like:&lt;/font&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&amp;nbsp;&lt;br&gt;&lt;a href="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/CreatingacustomdatacollectioninSQLServer_11336/image_4.png"&gt;&lt;img src="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/CreatingacustomdatacollectioninSQLServer_11336/image_thumb_1.png" style="border-width:0px;" alt="image" border="0" height="484" width="536"&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That's it. In the next part, we will look at reporting off of this collection through tsql and SSRS.&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:640103f8-7ed1-4b69-ad64-90533c203c40" style="margin:0px;padding:0px;display:inline;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SQL%20Server%202008" rel="tag"&gt;SQL Server 2008&lt;/a&gt;&lt;/div&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=7363" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="SQL Server 2008" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQL+Server+2008/default.aspx" /><category term="CTP5" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/CTP5/default.aspx" /><category term="Data Collections" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Data+Collections/default.aspx" /></entry><entry><title>SQL Server 2008 performance data collection in 5 minutes</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/15/sql-server-2008-performance-data-collection-in-5-minutes.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/15/sql-server-2008-performance-data-collection-in-5-minutes.aspx</id><published>2008-02-15T06:28:00Z</published><updated>2008-02-15T06:28:00Z</updated><content type="html">&lt;p&gt;This will be a quick and dirty post on data collection in SQL Server 2008. The next two posts will cover creating custom data collection sets and integrating reporting services. For a deeper understanding of data collections, check out Bill Ramos's web cast. He talks about it in &lt;a href="http://blogs.msdn.com/sqlrem/archive/2008/01/17/performance-studio-for-sql-server-2008-revealed.aspx" target="_blank"&gt;this post.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Data collection is basically a separate application that collects data about your SQL Server 2008 server, stores in SQL Server and provides reporting. It is like some of those 3rd party applications by vendors like Quest and Idera. It is fairly simple in design. This will allow you to easily get up to speed and extend. That is where it may excel over the 3rd party products.&lt;/p&gt;  &lt;p&gt;The moving parts include an executable called dcexe.exe, a warehouse database, SSIS, SQL Agent jobs and your data sources. The sources can be perfmon counters, DMV's,SQL traces and even application data. It was designed to minimize the stress on the source system but the warehouse database should reside on a different system.&lt;/p&gt;  &lt;p&gt;This feature comes with 3(as of right now) system collections. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Disk usage&lt;/b&gt; - this one basically logs the info from a sp_spaceused for each db. They say that disk space related performance counters may end up in here as well. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Query Statistics &lt;/b&gt;- This is "notable" queries from the procedure cache. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Server Activity&lt;/b&gt; - This collects data from system and OS perform counters as well as the SQLOS DMV's. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For a deeper discussion of this topic, please check out the web cast. The next post will demo setting up a custom collection. Part 3 will be on reporting off of the data collection.&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:04df9945-c8b3-47c6-ad05-2ef01040443f" style="margin:0px;padding:0px;display:inline;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SQL%20Server%202008" rel="tag"&gt;SQL Server 2008&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;* Cross posted from &lt;a href="http://statisticsio.com"&gt;http://statisticsio.com&lt;/a&gt; *&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=7362" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="SQL Server 2008" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQL+Server+2008/default.aspx" /><category term="CTP5" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/CTP5/default.aspx" /><category term="Data Collections" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Data+Collections/default.aspx" /></entry><entry><title>Migrating your SQL Cluster to a new SAN</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/13/migrating-your-sql-cluster-to-a-new-san.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/02/13/migrating-your-sql-cluster-to-a-new-san.aspx</id><published>2008-02-14T02:14:17Z</published><updated>2008-02-14T02:14:17Z</updated><content type="html">&lt;p&gt;There is a nice utility that does a lot of the heavy lifting for you when migrating your cluster to a new SAN. It is ClusterRecovery.exe. It is designed for replacing a failed disk but when you migrate to a new SAN, you have to go through the same steps. It basically moves all of the meta data like dependencies. The utility can be found the Win2k3 resource kit.&lt;/p&gt;  &lt;p&gt;The basic steps are:&lt;/p&gt;  &lt;p&gt;1. Present storage.&lt;/p&gt;  &lt;p&gt;2. Partition\format\letter. Pick any free letter. We will swap letters later. Let's choose h:\.&lt;/p&gt;  &lt;p&gt;3. Stop SQL and move data from old SAN to new SAN.&lt;/p&gt;  &lt;p&gt;4. Add the h:\ drive to&amp;#160; the SQL cluster group. &lt;/p&gt;  &lt;p&gt;5. Run the cluster recovery tool, connect to the cluster. Choose the old and new drive.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/MigratingyourSQLClustertoanewSAN_11C9F/image_4.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="237" alt="image" src="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/MigratingyourSQLClustertoanewSAN_11C9F/image_thumb_1.png" width="354" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;6. Open disk management, change the original g:\ drive to a different letter.&lt;/p&gt;  &lt;p&gt;7. Change the new drive's letter to the letter of the original drive's letter. h:\ to g:\ in our example.&lt;/p&gt;  &lt;p&gt;8. Bring the drives and services online.&lt;/p&gt;  &lt;p&gt;9. Remove the old drive resource with the &amp;quot;(lost)&amp;quot; suffice.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;That is about it.&lt;/p&gt;  &lt;p&gt;* Cross posted from &lt;a href="http://statisticsio.com"&gt;http://statisticsio.com&lt;/a&gt; *&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:04e249e1-b179-4aca-b15a-5eca076ea2f5" style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SQL%20Server" rel="tag"&gt;SQL Server&lt;/a&gt;,&lt;a href="http://technorati.com/tags/windows%20clustering" rel="tag"&gt;windows clustering&lt;/a&gt;&lt;/div&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=7309" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="Windows" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Windows/default.aspx" /></entry><entry><title>2008 to RTM next week</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/31/2008-to-rtm-next-week.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/31/2008-to-rtm-next-week.aspx</id><published>2008-01-31T23:52:00Z</published><updated>2008-01-31T23:52:00Z</updated><content type="html">&lt;p&gt;Windows Server 2008, that is. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;"&lt;/p&gt;    &lt;p&gt;Windows Server 2008 (and Vista Service Pack 1) are slated to release to manufacturing (RTM) on Feb. 6, according to several sources. That gives the company plenty of time to churn out disks for distribution at the event, which Microsoft executives have characterised as the company's "&lt;a href="http://channelmarker.blogs.techtarget.com/2007/07/10/"&gt;biggest enterprise launch ever&lt;/a&gt;."&lt;/p&gt;    &lt;p&gt;The early February RTM means that the long-awaited server operating system will be available for the big event. Visual Studio 2008 is already out. Microsoft last week said SQL Server 2008 has slipped into the third quarter. Previously, the company said the database would be available in the second quarter. Microsoft has also promised to deliver its new database release in 36 to 48 months going forward. SQL Server 2003 shipped in November of that year."&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The full story can be found &lt;a href="http://searchnetworking.techtarget.com.au/topics/article.asp?DocID=1296646" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;table cellpadding="1" cellspacing="0"&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p align="center"&gt;&lt;a href="http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=6d7b361bf17ee329%40apps.messenger.live.com" target="_blank"&gt;&lt;img src="http://messenger.services.live.com/users/6d7b361bf17ee329@apps.messenger.live.com/presenceimage" alt="Click to IM Jason Massie" border="0"&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p align="center"&gt;&lt;a href="http://www.facebook.com/people/Jason_Massie/1013730310" target="_blank"&gt;&lt;img src="http://static.ak.facebook.com/images/icons/favicon.gif"&gt;&lt;/a&gt; &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p align="center"&gt;&lt;a href="http://feeds.feedburner.com/statisticsio" rel="alternate"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" style="border-width:0px;vertical-align:middle;" alt=""&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://feeds.feedburner.com/statisticsio" rel="alternate"&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p align="center"&gt;&lt;a href="http://www.linkedin.com/in/jasonmassie" style="text-decoration:none;"&gt;&lt;span style="font-family:arial,sans-serif;font-style:normal;font-variant:normal;font-weight:normal;font-size:80%;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;&lt;img src="http://www.linkedin.com/img/webpromo/btn_in_20x15.gif" style="vertical-align:middle;" alt="View Jason Massie's LinkedIn profile" border="0" height="15" width="20"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;&amp;nbsp;&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;* cross posted from &lt;a href="http://statisticsio.com"&gt;http://statisticsio.com&lt;/a&gt; *&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=6556" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="Windows" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Windows/default.aspx" /></entry><entry><title>Never use table variables?</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/29/never-use-table-variables.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/29/never-use-table-variables.aspx</id><published>2008-01-30T04:02:00Z</published><updated>2008-01-30T04:02:00Z</updated><content type="html">&lt;p&gt;MS pushed tables variables too hard back in 2000 and developers went a little crazy with them. However, we found out that they were not the greatest thing since sliced bread especially when the result set is more that a few records and the query is even mildly complex. &lt;/p&gt;  &lt;p&gt;The other case we hear for table variables is to avoid recompilations. This was true in SQL Server 2000. This has changed somewhat in SQL 2005 but you might not realize this by reading some web sites out there. On top of that, I cannot reproduce recompiles until much higher thresholds than what we should see per the documentation. This is a good thing in most scenarios IMO. &lt;/p&gt;  &lt;p&gt;Based on this &lt;a href="http://blogs.msdn.com/sqlprogrammability/archive/2007/01/18/11-0-temporary-tables-table-variables-and-recompiles.aspx" target="_blank"&gt;blog post&lt;/a&gt;, which is part of a great &lt;a href="http://blogs.msdn.com/sqlprogrammability/archive/tags/Procedure+Cache/default.aspx" target="_blank"&gt;procedure cache&lt;/a&gt; series, we should see a recompile when 6 rows change, 500 more and at 500 + 0.20 * n more where n is the cardinality of the table.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;"&lt;/p&gt;    &lt;p&gt;After 6 modifications to an empty temporary table any stored procedure referencing that temporary table will need to be recompiled because the temporary table statistics needs to be refreshed. &lt;/p&gt;    &lt;p&gt;The recompilation threshold for a table partly determines the frequency with which queries that refer to the table recompile. Recompilation threshold depends on the table type (permanent vs temporary), and the cardinality (number of rows in the table) when a query plan is compiled. The recompilation thresholds for all of the tables referenced in a batch are stored with the query plans of that batch. &lt;/p&gt;    &lt;p&gt;Recompilation threshold is calculated as follows for temporary tables: n is the cardinality of the temporary table when the query plan is compiled.&lt;/p&gt;    &lt;p&gt;If n &amp;lt; 6, Recompilation threshold = 6.&lt;/p&gt;    &lt;p&gt;If 6 &amp;lt;= n &amp;lt;= 500, Recompilation threshold = 500.&lt;/p&gt;    &lt;p&gt;If n &amp;gt; 500, Recompilation threshold = 500 + 0.20 * n.&lt;/p&gt;    &lt;p&gt;"&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That blog post mirrors the numbers in this &lt;b&gt;must read&lt;/b&gt;&amp;nbsp;&lt;a href="http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx#LiveContent%5BSTATS%5D" target="_blank"&gt;white paper&lt;/a&gt;.&amp;nbsp; Both the blog and the white paper, use this example.&lt;/p&gt;&lt;pre&gt;create procedure RowCountDemo &lt;br&gt;as &lt;br&gt;begin &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;create table #t1 (a int, b int) &lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;declare @i int &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set @i = 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (@i &amp;lt; 20) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;begin &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into #t1 values (@i, 2*@i - 50) &lt;br&gt; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from #t1  &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a &amp;lt; 10 or ((b &amp;gt; 20 or a &amp;gt;=100) and (a &amp;lt; 10000)) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a &lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set @i = @i + 1 &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end &lt;br&gt;end &lt;/pre&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/font&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;&lt;font color="#000000" size="2"&gt;Now here is the interesting part... I cannot get it to recompile. I have tried on SQL 2005 RTM, sp2 and sp2 + 3054. The initial run shows up as a recompile in a trace but subsequent runs do not. Not at @i = 100, 500 or 1000. At precisely @i = 1108, recompilation happens every time.&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;alter procedure RowCountDemo &lt;br&gt;as &lt;br&gt;begin &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table #t1 (a int, b int) &lt;br&gt;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare @i int &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set @i = 0&amp;nbsp;&amp;nbsp;&amp;nbsp; while (@i &amp;lt; 1108) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into #t1 values (@i, 2*@i - 50) &lt;br&gt;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from #t1&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a &amp;lt; 10 or ((b &amp;gt; 20 or a &amp;gt;=100) and (a &amp;lt; 10000)) &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a &lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set @i = @i + 1 &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end &lt;br&gt;end&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font color="#000000" size="2"&gt;Now there may be something totally flawed in my understanding. I am sure you guys will point that out if it is the case :) But the white paper states:&lt;/font&gt;    &lt;blockquote&gt;     &lt;p&gt;&lt;font color="#000000" size="2"&gt;"Recall that the recompilation threshold for a temporary table is 6 when the table is empty when the threshold is calculated. When RowCountDemo is executed, a "statistics changed"-related recompilation can be observed after #t1 contains exactly 6 rows. By changing the upper bound of the "while" loop, more recompilations can be observed."&lt;/font&gt;&lt;/p&gt;   &lt;/blockquote&gt;    &lt;p&gt;&lt;font color="#000000" size="2"&gt;If temp tables really do not cause recompilations at 6 rows, I really cannot think of a good reason to use table variables except for small sets and then only out of preference&lt;b&gt;.&lt;/b&gt; &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#000000" size="2"&gt;&lt;/font&gt;&lt;/p&gt;    &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f0000d79-0e49-4ad8-b663-347b08307da5" style="margin:0px;padding:0px;display:inline;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SQL%20Server" rel="tag"&gt;SQL Server&lt;/a&gt;,&lt;a href="http://technorati.com/tags/temp%20tables" rel="tag"&gt;temp tables&lt;/a&gt;&lt;/div&gt;    &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt;IMMe:&lt;/font&gt; &lt;/font&gt;&lt;a href="http://statisticsio.com" target="_blank"&gt;&lt;font size="2"&gt;Jason Massie&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;a href="http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=6d7b361bf17ee329%40apps.messenger.live.com" target="_blank"&gt;&lt;font size="2"&gt;&lt;img src="http://messenger.services.live.com/users/6d7b361bf17ee329@apps.messenger.live.com/presenceimage" alt="Click to IM Jason Massie" border="0"&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;        &lt;p&gt;&lt;font size="2"&gt;&amp;nbsp;&lt;/font&gt;&lt;a href="http://www.linkedin.com/in/jasonmassie"&gt;&lt;font size="2"&gt;&lt;img src="http://www.linkedin.com/img/webpromo/btn_linkedin_120x30.gif" alt="View Jason Massie's profile on LinkedIn" border="0" height="30" width="120"&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;br&gt;&lt;span id="dnn_ctr369_MainView_ViewEntry_lblEntry"&gt;&lt;br&gt;&lt;a href="http://feeds.feedburner.com/statisticsio" title="Subscribe to my feed" rel="alternate"&gt;&lt;img src="http://www.feedburner.com/fb/images/pub/feed-icon32x32.png" alt="" style="border:0pt none;"&gt;&lt;/a&gt;&lt;a href="http://feeds.feedburner.com/statisticsio" title="Subscribe to my feed" rel="alternate"&gt;Subscribe&lt;/a&gt;&lt;/span&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;* cross posted from &lt;a href="http://statisticsio.com"&gt;http://statisticsio.com&lt;/a&gt; *&lt;br&gt;&lt;/p&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=6482" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="PerformanceTuning" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/PerformanceTuning/default.aspx" /><category term="query optimizer" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/query+optimizer/default.aspx" /><category term="temp tables" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/temp+tables/default.aspx" /><category term="Death to table variables" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Death+to+table+variables/default.aspx" /></entry><entry><title>SQL Server 2008 RTM delayed until Q3</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/25/sql-server-2008-rtm-delayed-until-q3.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/25/sql-server-2008-rtm-delayed-until-q3.aspx</id><published>2008-01-25T20:24:00Z</published><updated>2008-01-25T20:24:00Z</updated><content type="html">&lt;blockquote&gt;   &lt;p&gt;"&lt;/p&gt;    &lt;p&gt;Microsoft is excited to deliver a feature complete CTP during the Heroes Happen Here launch wave and a release candidate (RC) in Q2 calendar year 2008, with final Release to manufacturing (RTM) of SQL Server 2008 expected in Q3. Our goal is to deliver the highest quality product possible and we simply want to use the time to meet the high bar that you, our customers, expect.&lt;/p&gt;    &lt;p&gt;"&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/dataplatforminsider/archive/2008/01/25/microsoft-sql-server-2008-roadmap-clarification.aspx" target="_blank"&gt;Read more&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;nbsp;*cross posted from &lt;a href="http://statisticsio.com"&gt;http://statisticsio.com&lt;/a&gt; *&lt;br&gt;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a864040a-656d-443e-9acd-37d68ae826c6" style="margin:0px;padding:0px;display:inline;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SQL%20Server%202008" rel="tag"&gt;SQL Server 2008&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Heroes%20Happen%20Here" rel="tag"&gt;Heroes Happen Here&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c495cb8b-2a34-4982-bf02-f5c02c225f4f" style="margin:0px;padding:0px;display:inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/SQL%20Server%202008" rel="tag"&gt;SQL Server 2008&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/Heroes%20Happen%20Here" rel="tag"&gt;Heroes Happen Here&lt;/a&gt;&lt;/div&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=6392" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="SQL Server 2008" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQL+Server+2008/default.aspx" /></entry><entry><title>The problem with local variables</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/25/the-problem-with-local-variables.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/25/the-problem-with-local-variables.aspx</id><published>2008-01-25T07:56:00Z</published><updated>2008-01-25T07:56:00Z</updated><content type="html">
&lt;p&gt;Have you ever been writing a query and just cannot get it to use the right index? This could be one of the reasons why. Let's use this query with local variables as our example.&lt;/p&gt;
  
&lt;pre class="csharpcode"&gt;declare @Start datetime&lt;br&gt;declare @End datetime&lt;br&gt;select @Start = '2004-08-01 00:00:00.000'&lt;br&gt;select @End = '2004-07-28 00:00:00.000'&lt;br&gt;select ProductID from sales.SalesOrderDetail&lt;br&gt;where ModifiedDate &amp;gt;= @End and ModifiedDate &amp;lt;= @Start&lt;br&gt;&amp;nbsp;&lt;/pre&gt;


&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/Theproblemwithlocalvariables_15AB/image_4.png"&gt;&lt;img src="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/Theproblemwithlocalvariables_15AB/image_thumb_1.png" style="border-width:0px;" alt="SQL Server Clustered index scan" border="0" height="77" width="306"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;but we have an index on ModifiedDate. There are many reason why SQL would not use this index but, for this post, we will assume we have eliminated them. Finally, we hard code the dates and we get this plan.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/Theproblemwithlocalvariables_15AB/image_6.png"&gt;&lt;img src="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/Theproblemwithlocalvariables_15AB/image_thumb_2.png" style="border-width:0px;" alt="SQL Server index seek with bookmark lookup" border="0" height="114" width="393"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So why is it doing this? The reason is because the query optimizer cannot accurately use the statistics to estimate how many rows are returned with local variables. Let's look at how we can tell there is a problem with the cardinality estimates. In the query with the local variables, the optimizer thinks we are getting 10918.5 rows so we do the index scan. In the query with hard coded literals, the estimated rows and actual rows are the same and accurate.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://sqlblogcasts.com/blogs/jasonmassie/WindowsLiveWriter/Theproblemwithlocalvariables_15AB/image_13.png" style="border-width:0px;" alt="SQL Server Cardinality underestimation" border="0" height="297" width="292"&gt; &lt;/p&gt;

&lt;p&gt;How can we fix this? There are several way. This is another situation that makes a case for stored procedures or parameterized queries.&lt;/p&gt;

&lt;p&gt;create proc pDemo01&lt;br&gt;@Start datetime,&lt;br&gt;@End datetime&lt;br&gt;as&lt;br&gt;select ProductID from sales.SalesOrderDetail&lt;br&gt;where ModifiedDate &amp;gt;= @End and ModifiedDate &amp;lt;= @Start&lt;br&gt;&lt;br&gt;&lt;br&gt;exec pDemo01 '2004-08-01 00:00:00.000', '2004-07-28 00:00:00.000' &lt;br&gt;&lt;/p&gt;



&lt;p&gt;The stored proc generates the proper plan. However, you will run into the same problem if you modify the parameter within the stored proc like select @start = @start-90. In this case, to should use sp_executeSQL. What if you cannot use a stored proc because it is a 3rd party app or some other reason? A covering index is probably the solution. Once we create this index, it will always be used:&lt;/p&gt;

&lt;p&gt;create index ix01 on sales.SalesOrderDetail(ModifiedDate) include (ProductID)&lt;/p&gt;

&lt;p&gt;We could use a plan guide or an index hint with a forceseek(SQL 2008)&amp;nbsp; but performance will be really bad when we really do need to get 10k rows. The same problem can happen with stored proc's but that is another post.&lt;/p&gt;

&lt;p&gt;To get deeper into this subject, check out &lt;a href="http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx#LiveContent%5BSTATS%5D" target="_blank"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;*Cross posted from &lt;a href="http://statisticsio.com" target="_blank"&gt;http://statisticsio.com&lt;/a&gt; *&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f1358ef5-a8e4-48a2-80bd-d2775c78398e" style="margin:0px;padding:0px;display:inline;float:none;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/stored%20procedures" rel="tag"&gt;stored procedures&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Cardinality" rel="tag"&gt;Cardinality&lt;/a&gt;,&lt;a href="http://technorati.com/tags/query%20optimizer" rel="tag"&gt;query optimizer&lt;/a&gt;,&lt;a href="http://technorati.com/tags/local%20variables" rel="tag"&gt;local variables&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SQL%20Server" rel="tag"&gt;SQL Server&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3635235b-6d5d-4ef4-b9fa-22bd7fe6c330" style="margin:0px;padding:0px;display:inline;"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/stored%20procedures" rel="tag"&gt;stored procedures&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/Cardinality" rel="tag"&gt;Cardinality&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/query%20optimizer" rel="tag"&gt;query optimizer&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/local%20variables" rel="tag"&gt;local variables&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/SQL%20Server" rel="tag"&gt;SQL Server&lt;/a&gt;&lt;/div&gt;&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3635235b-6d5d-4ef4-b9fa-22bd7fe6c330" style="margin:0px;padding:0px;display:inline;"&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3635235b-6d5d-4ef4-b9fa-22bd7fe6c330" style="margin:0px;padding:0px;display:inline;"&gt;&amp;nbsp;&lt;/div&gt;&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3635235b-6d5d-4ef4-b9fa-22bd7fe6c330" style="margin:0px;padding:0px;display:inline;"&gt;&amp;nbsp;&lt;/div&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=6372" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="Indexes" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Indexes/default.aspx" /><category term="tsql" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/tsql/default.aspx" /><category term="Performance" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Performance/default.aspx" /><category term="Plan guides" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Plan+guides/default.aspx" /><category term="query optimizer" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/query+optimizer/default.aspx" /></entry><entry><title>SQL Server 2008 Plan Guides from Cache</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/18/sql-server-2008-plan-guides-from-cache.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/18/sql-server-2008-plan-guides-from-cache.aspx</id><published>2008-01-18T07:00:00Z</published><updated>2008-01-18T07:00:00Z</updated><content type="html">&lt;P&gt;Uhoh... I can see some junior developers going crazy with this. One of the things that kept plan guides from being over used was the fact that they are kind of hard :) Well, Microsoft built their empire making hard stuff easy. They do it again with sp_create_plan_guide_from_cache.&lt;/P&gt;
&lt;P&gt;Let's look at this BOL sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;USE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; AdventureWorks&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; WorkOrderID&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Name&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; OrderQty&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; DueDate&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; Production&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;WorkOrder &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; w &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;JOIN&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; Production&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Product &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; p &lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt; w&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductID &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductID&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductSubcategoryID &lt;SPAN style="COLOR:gray;"&gt;&amp;gt;&lt;/SPAN&gt; 4&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;ORDER&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:blue;"&gt;BY&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Name&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; DueDate&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;-- Inspect the query plan by using dynamic management views.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt; &lt;SPAN style="COLOR:green;"&gt;sys.dm_exec_query_stats&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; qs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;CROSS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;APPLY&lt;/SPAN&gt; sys.dm_exec_sql_text&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;sql_handle&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;CROSS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;APPLY&lt;/SPAN&gt; sys.dm_exec_text_query_plan&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;plan_handle&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_start_offset&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_end_offset&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; qp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:blue;"&gt;text&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;LIKE&lt;/SPAN&gt; N&lt;SPAN style="COLOR:red;"&gt;'SELECT WorkOrderID, p.Name, OrderQty, DueDate%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;-- Create a plan guide for the query by specifying the query plan in the plan cache.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;DECLARE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; @plan_handle &lt;SPAN style="COLOR:blue;"&gt;varbinary&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;64&lt;SPAN style="COLOR:gray;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;DECLARE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; @offset &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; @plan_handle &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; plan_handle&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; @offset &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_start_offset&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:green;"&gt;sys.dm_exec_query_stats&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; qs&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;CROSS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;APPLY&lt;/SPAN&gt; sys.dm_exec_sql_text&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;sql_handle&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; st&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;CROSS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;APPLY&lt;/SPAN&gt; sys.dm_exec_text_query_plan&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;plan_handle&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_start_offset&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; qs&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_end_offset&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; qp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:blue;"&gt;text&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;LIKE&lt;/SPAN&gt; N&lt;SPAN style="COLOR:red;"&gt;'SELECT WorkOrderID, p.Name, OrderQty, DueDate%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;EXECUTE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; sp_create_plan_guide_from_cache &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@name &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;N&lt;SPAN style="COLOR:red;"&gt;'Guide1'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@plan_handle &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @plan_handle&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;@statement_start_offset &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; @offset&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;-- Verify that the plan guide is created.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt; &lt;SPAN style="COLOR:green;"&gt;sys.plan_guides&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; scope_batch &lt;SPAN style="COLOR:gray;"&gt;LIKE&lt;/SPAN&gt; N&lt;SPAN style="COLOR:red;"&gt;'SELECT WorkOrderID, p.Name, OrderQty, DueDate%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;--Let's verify it actually worked.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;--Click the xml link&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;--Save as a .sqlplan, reopen in SSMS and then hit f4&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:blue;"&gt;statistics&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;xml&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;on&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; WorkOrderID&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Name&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; OrderQty&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; DueDate&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; Production&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;WorkOrder &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; w &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;JOIN&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; Production&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Product &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; p &lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt; w&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductID &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductID&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;ProductSubcategoryID &lt;SPAN style="COLOR:gray;"&gt;&amp;gt;&lt;/SPAN&gt; 4&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN-BOTTOM:0pt;LINE-HEIGHT:normal;"&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;ORDER&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt; &lt;SPAN style="COLOR:blue;"&gt;BY&lt;/SPAN&gt; p&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Name&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; DueDate&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;"&gt;GO&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV align=center&gt;&lt;IMG height=444 alt="" src="http://statisticsio.com/Portals/0/sqlplan.jpg" width=1079&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal&gt;So when would you use this? I would say hardly ever hopefully. However, it could solve the really tough problems.&lt;/P&gt;
&lt;P class=MsoNormal&gt;Let's say you have a 3rd party application that generates adhoc dynamic SQL. You cannot modify the code or schema. Index changes are not supported. Sometimes parameter sniffing causes unpredictable performance. Sound like a nightmare? Welcome to most CRM apps.&lt;/P&gt;
&lt;P class=MsoNormal&gt;Other scenarios that come to mind are when best practices are not or cannot be followed. Let's say you just cannot update stats often enough with a large enough sample on a very very VERY large table to get a consistently optimal plan. Use a plan guide!&lt;/P&gt;
&lt;P class=MsoNormal&gt;Here are some other times that the optimizer might have trouble and a plan guide may be a good option.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use of local variables&lt;/LI&gt;
&lt;LI&gt;Modifying stored proc parameters.&lt;/LI&gt;
&lt;LI&gt;Ascending keys&lt;/LI&gt;
&lt;LI&gt;Complex queries with table variables&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;There are usually better solutions than plan guides so save them for times that best practices are not an option. sp_create_plan_guide_from_cache makes using plan guides so much easier. Put it in your toolbox!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;**Cross Posted from &lt;A href="http://statisticsio.com/"&gt;http://statisticsio.com&lt;/A&gt; **&lt;/P&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=6273" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="tsql" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/tsql/default.aspx" /><category term="Performance" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Performance/default.aspx" /><category term="SQL Server 2008" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQL+Server+2008/default.aspx" /><category term="CTP5" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/CTP5/default.aspx" /><category term="Plan guides" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Plan+guides/default.aspx" /></entry><entry><title>SQL Connections Spring 2008</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/12/12/sql-connections-spring-2008.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/12/12/sql-connections-spring-2008.aspx</id><published>2007-12-12T22:16:00Z</published><updated>2007-12-12T22:16:00Z</updated><content type="html">&lt;span id="dnn_ctr369_MainView_ViewEntry_lblEntry" class="Normal"&gt;&lt;p&gt;I
am speaking SQL Connections in Orlando this April. The session is
entitled "Augmenting the DBA toolbox with SSRS" It will be similar to
my pass session except it is all about Reporting Services and it
will be 100% SQL 2008. However, most reports will be 2005 compatible with
minor changes. It will totally be about working smarter not harder. I
will have a ton of tools that you can integrate into your environment
and I will show you how to put your existing tools to work.&lt;/p&gt;&lt;p&gt;I am really excited about this. I missed this year but I went in 2006 and 2005. For more infomation, check out &lt;a href="http://sqlconnections.com/shows/SP2008SQL/default.asp#LiveContent%5BSQLConn%5D" id="SQLConn" class="highslide"&gt;http://sqlconnections.com&lt;/a&gt; You can also read the co-chair blogs &lt;a href="http://sqlskills.com/blogs/kimberly#LiveContent%5BKT%5D" id="KT" class="highslide"&gt;here&lt;/a&gt; and &lt;a href="http://sqlskills.com/blogs/paul#LiveContent%5BPR%5D" id="PR" class="highslide"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;*Cross posted*&lt;/p&gt;&lt;p&gt;&lt;a href="http://statisticsio.com" target="_blank"&gt;http://statisticsio.com&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/span&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=5478" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="SQLConnections SSRS" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/SQLConnections+SSRS/default.aspx" /></entry><entry><title>A quick and dirty WTF???!!!11one</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/12/07/a-quick-and-dirty-wtf-11one.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/12/07/a-quick-and-dirty-wtf-11one.aspx</id><published>2007-12-07T21:30:00Z</published><updated>2007-12-07T21:30:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-FAMILY:'Calibri','sans-serif';"&gt;&lt;FONT size=3&gt;You can use this to get a quick and dirty picture of what is going on with the server. We basically grab a snapshot, wait a second and then get a diff. Sort as needed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY:'Calibri','sans-serif';"&gt;&lt;FONT size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;cpu_time &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;logical_reads&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;into&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; #temp&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:green;"&gt;sys.dm_exec_requests&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; r &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;waitfor&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;delay&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'00:00:01'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:red;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;text&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_start_offset&lt;SPAN style="COLOR:gray;"&gt;/&lt;/SPAN&gt;2&lt;SPAN style="COLOR:gray;"&gt;)+&lt;/SPAN&gt;1 &lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;((&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;case&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_end_offset &lt;SPAN style="COLOR:blue;"&gt;when&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;-&lt;/SPAN&gt;1 &lt;SPAN style="COLOR:blue;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;datalength&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;h&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;text&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;else&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_end_offset &lt;SPAN style="COLOR:blue;"&gt;end&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;-&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;statement_start_offset&lt;SPAN style="COLOR:gray;"&gt;)/&lt;/SPAN&gt;2&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; 1&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;text&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;cpu_time&lt;SPAN style="COLOR:gray;"&gt;-&lt;/SPAN&gt;t&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;cpu_time &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; CPUDiff &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;logical_reads&lt;SPAN style="COLOR:gray;"&gt;-&lt;/SPAN&gt;t&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;logical_reads &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; ReadDiff&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;wait_type&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;wait_time&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;last_wait_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;wait_resource&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;command&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;database_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;blocking_session_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;granted_query_memory&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;reads&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;writes&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;row_count&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;[host_name]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:fuchsia;"&gt;program_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-tab-count:1;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;login_name&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:green;"&gt;sys.dm_exec_sessions&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; s &lt;SPAN style="COLOR:gray;"&gt;inner&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;join&lt;/SPAN&gt; &lt;SPAN style="COLOR:green;"&gt;sys.dm_exec_requests&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; r &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;on&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id &lt;SPAN style="COLOR:gray;"&gt;and&lt;/SPAN&gt; s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;last_request_start_time&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;start_time&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:gray;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;left&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;join&lt;/SPAN&gt; #temp &lt;SPAN style="COLOR:blue;"&gt;as&lt;/SPAN&gt; t &lt;SPAN style="COLOR:blue;"&gt;on&lt;/SPAN&gt; t&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;s&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;session_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:gray;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;CROSS&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;APPLY&lt;/SPAN&gt; sys.dm_exec_sql_text&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;r&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;sql_handle&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; h&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; is_user_process &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;order&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;by&lt;/SPAN&gt; 3 &lt;SPAN style="COLOR:blue;"&gt;desc&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:9pt;COLOR:blue;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;table&lt;/SPAN&gt; #temp&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;*note*&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:9pt;FONT-FAMILY:'Terminal','serif';mso-no-proof:yes;"&gt;cross posted from &lt;A href="http://statisticsio.com/"&gt;http://statisticsio.com&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=5325" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="Indexes" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Indexes/default.aspx" /><category term="DMV" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/DMV/default.aspx" /><category term="tsql" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/tsql/default.aspx" /><category term="Performance" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Performance/default.aspx" /><category term="reactive" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/reactive/default.aspx" /></entry><entry><title>Accessing OS performance counters from tsql</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/11/29/accessing-os-performance-counters-from-tsql.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/11/29/accessing-os-performance-counters-from-tsql.aspx</id><published>2007-11-30T01:03:00Z</published><updated>2007-11-30T01:03:00Z</updated><content type="html">&lt;SPAN class=Normal id=dnn_ctr369_MainView_ViewEntry_lblEntry&gt;&amp;nbsp; 
&lt;P class=MsoNormal&gt;A cool use of WMI data from within SQL that I have found is getting to OS perfmon data. There are several ways of doing it. I would say the best practice would be CLR if you need it in real time or SSIS if you are logging to a table for reporting purposes. You can also hit it through xp_cmdshell and powershell. This is what I do when I need it quick.&lt;/P&gt;
&lt;P class=MsoNormal&gt;In this blog, we will look at an example of doing this in CLR. &lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;We will be using % processor time but any perform counter is available. &lt;A class=highslide id=PerfCounters href="http://msdn2.microsoft.com/en-us/library/aa392738.aspx#LiveContent%5BPerfCounters%5D"&gt;A list is here.&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:8pt;LINE-HEIGHT:115%;"&gt;DISCLAIMER: I am definitely not a CLR guru. If you know of a better way to code this, please let me know.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;Here are some uses. The first two I have in production.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A server dashboard with reporting services. 
&lt;LI&gt;A resource governor to conditionally execute tasks like index\stats maintenance. 
&lt;LI&gt;Home grown monitoring apps 
&lt;LI&gt;Integration with your backup to dynamically choose drive based on space. 
&lt;LI&gt;Insert your idea here.&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal&gt;So let’s do this.&lt;/P&gt;&lt;SPAN style="FONT-SIZE:10pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--Create Database&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;create&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;database&lt;/SPAN&gt; WMITest01;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--Enable CLR&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;exec&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; sp_configure &lt;SPAN style="COLOR:red;"&gt;'clr enabled'&lt;/SPAN&gt;, 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;reconfigure&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;with&lt;/SPAN&gt; override&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--Enable trust worthy computing&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--This allows us to create assemblies that access resources outside of the database.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;alter&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;database&lt;/SPAN&gt; WMITest01&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; trustworthy&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;on&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;--This assemby allows us to use WMI in CLR functions and procs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;use&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; wmitest01&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;ASSEMBLY&lt;/SPAN&gt; [System.Management]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;AUTHORIZATION&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; [dbo]&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:red;"&gt;'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Management.dll'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;WITH&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; PERMISSION_SET = UNSAFE&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Now, we are going create a new VB(or C# but the sample code is VB) database project in Visual Studio 2005. Now do the following steps:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Add a reference to the WMITest database&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Set the project properties to unsafe so we can add a reference to System.Management&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Add a database reference to System.Management&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Create a new stored procedure&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN:0in 0in 0pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;5.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Replace the code with the follow code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN:0in 0in 10pt 0.5in;TEXT-INDENT:-0.25in;mso-list:l0 level1 lfo1;"&gt;&lt;SPAN style="mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT face=Calibri size=3&gt;6.&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Deploy&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; System&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; System.Data&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; System.Management&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; System.Data.SqlClient&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; System.Data.SqlTypes&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Imports&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; Microsoft.SqlServer.Server&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;Public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;Class&lt;/SPAN&gt; ProcTimeStoredProcedures&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;lt;Microsoft.SqlServer.Server.SqlProcedure()&amp;gt; _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;Public&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;Shared&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;Sub&lt;/SPAN&gt; pnetWMIProcTime()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;Dim&lt;/SPAN&gt; searcher &lt;SPAN style="COLOR:blue;"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;New&lt;/SPAN&gt; ManagementObjectSearcher( _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#a31515;"&gt;"root\CIMV2"&lt;/SPAN&gt;, _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:#a31515;"&gt;"select PercentProcessorTime from Win32_PerfFormattedData_PerfOS_Processor where name = '_Total'"&lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;For&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;Each&lt;/SPAN&gt; queryObj &lt;SPAN style="COLOR:blue;"&gt;As&lt;/SPAN&gt; ManagementObject &lt;SPAN style="COLOR:blue;"&gt;In&lt;/SPAN&gt; searcher.Get()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;Dim&lt;/SPAN&gt; record &lt;SPAN style="COLOR:blue;"&gt;As&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;New&lt;/SPAN&gt; SqlDataRecord( _&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;New&lt;/SPAN&gt; SqlMetaData(&lt;SPAN style="COLOR:#a31515;"&gt;"PercentProcessorTime "&lt;/SPAN&gt;, SqlDbType.VarChar, 100))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SqlContext.Pipe.SendResultsStart(record)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;record.SetString(0, queryObj(&lt;SPAN style="COLOR:#a31515;"&gt;"PercentProcessorTime"&lt;/SPAN&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SqlContext.Pipe.SendResultsRow(record)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;Next&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SqlContext.Pipe.SendResultsEnd()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;Sub&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;End&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;Class&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;So now we can run &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:10pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;pnetWMIProcTime&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt; and know what the current CPU usage is from within SQL.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;*Cross posted from &lt;A href="http://statisticsio.com/"&gt;http://statisticsio.com&lt;/A&gt; *&lt;/FONT&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=4989" width="1" height="1"&gt;</content><author><name>JasonMassie</name><uri>http://sqlblogcasts.com/members/JasonMassie.aspx</uri></author><category term="WMI" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/WMI/default.aspx" /><category term="tsql" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/tsql/default.aspx" /><category term="VB.net" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/VB.net/default.aspx" /><category term="CLR" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/CLR/default.aspx" /><category term="Performance" scheme="http://sqlblogcasts.com/blogs/jasonmassie/archive/tags/Performance/default.aspx" /></entry><entry><title>Take it a step further with the index DMV's</title><link rel="alternate" type="text/html" href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/11/25/take-it-a-step-further-with-the-index-dmv-s.aspx" /><id>http://sqlblogcasts.com/blogs/jasonmassie/archive/2007/11/25/take-it-a-step-further-with-the-index-dmv-s.aspx</id><published>2007-11-25T07:05:00Z</published><updated>2007-11-25T07:05:00Z</updated><content type="html">&lt;span id="dnn_ctr369_MainView_ViewEntry_lblEntry" class="Normal"&gt;&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;In SQL 2000 I wanted to find unused
indexes but found it to be difficult. I had to capture a huge trace that fully represents
the workload and “trust” that the ITW knows what it’s talking about. You could also
use the scan started trace event filtered by dbid, objectid, indexid. This procedure
was very tedious. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;In SS2005, a quick query of the
dynamic management views lets you know which indexes are not being used. You can
do this in a few minutes what had previously taken days or weeks. This alone is
a very powerful feature. &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;I am proposing that you take it
a step further. We are going to use a little logic and the missing index DMV’s to
combine indexes and remove indexes that are still used but redundant. The steps
in this process would look like this:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpFirst" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;1.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Remove unused indexes with the unused
index script&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;2.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Get your list of tables to analyze.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;3.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Remove redundant but used indexes.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;4.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Revue missing index DMV’s for mistaken
index drops.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;5.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Combine indexes that where it is
logical to do so.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpLast" style="margin:0in 0in 10pt 0.5in;text-indent:-0.25in;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;6.&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;Revue missing index DMV’s for mistaken
index drops.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;This methodology is most effective
and viable when these conditions are met:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpFirst" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
The server has been online and thus collecting stats for a long time.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
The server is not pushing a hardware bottleneck. If so, this should be done during
maint window.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpLast" style="margin:0in 0in 10pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
The server is enterprise edition and the tables allow online operations (i.e. no
LOB data or partitions).&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin:0in 0in 10pt;"&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;What are the benefits of removing
unused indexes?&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpFirst" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
Reduced writes during updates&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
Reduced space usage&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoListParagraphCxSpMiddle" style="margin:0in 0in 0pt 0.5in;text-indent:-0.25in;"&gt;&lt;span style="font-family:Symbol;"&gt;
&lt;span&gt;&lt;span style="font-size:11pt;"&gt;·&lt;/span&gt;&lt;span style="font-family:'Times New Roman';font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-size-adjust:none;font-stretch:normal;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:11pt;font-family:Calibri;"&gt;
Reduced backup\restore space and time&lt;/span