<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Strate SQL &#187; SQL Server 2005</title>
	<atom:link href="http://www.jasonstrate.com/index.php/tag/sql-server-2005/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonstrate.com</link>
	<description>Questions, answers, opinions and scripts from a SQL Server DBA</description>
	<lastBuildDate>Tue, 31 Aug 2010 02:56:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Find Tables and Columns by Data Type</title>
		<link>http://www.jasonstrate.com/index.php/2010/08/find-tables-and-columns-by-data-type/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/08/find-tables-and-columns-by-data-type/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 20:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/08/find-tables-and-columns-by-data-type/</guid>
		<description><![CDATA[A couple weeks back someone asked me some questions about data types.  Apparently, while implementing some financial data, each developer on the project had chosen their own data type.  This was a bit of a problem that can lead to serious problems.  When financial data is rounded unexpectedly &#8211; bad things can sometimes happen and [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/find-tables-with-forwarded-records/' rel='bookmark' title='Permanent Link: Find Tables with Forwarded Records'>Find Tables with Forwarded Records</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F08%2Ffind-tables-and-columns-by-data-type%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F08%2Ffind-tables-and-columns-by-data-type%2F" height="61" width="51" /></a></div><p><a title="old yellow eyes" href="http://www.flickr.com/photos/9450118@N03/4896224541/"><img style="display: inline; margin-left: 0px; margin-right: 0px;" src="http://static.flickr.com/4099/4896224541_14cf887469.jpg" border="0" alt="old yellow eyes" width="142" height="167" align="right" /></a>A couple weeks back someone asked me some questions about data types.  Apparently, while implementing some financial <a href="http://en.wikipedia.org/wiki/Data_(Star_Trek)">data</a>, each developer on the project had chosen their own data type.  This was a bit of a problem that can lead to serious problems.  When financial data is rounded unexpectedly &#8211; <a href="http://en.wikipedia.org/wiki/Superman_III">bad things can sometimes happen and it usually doesn’t involve plots for half pennies</a>.</p>
<p>Anyways, I advised that it might be a good idea to get all of the data types on these columns aligned. To do this I provided them with a couple scripts that are below that they used to find the occurrences of this information.  These scripts both use the <a href="http://msdn.microsoft.com/en-us/library/ms176106.aspx">sys.columns</a> and <a href="http://msdn.microsoft.com/en-us/library/ms188021.aspx">sys.types</a> catalog views.</p>
<p>This first script, pulls out all of the columns that are in the database using decimal, numeric, or money data type.  It includes a filter where scale is not equal to zero – which should have included all of the financial data.</p>
<pre class="brush: sql; ">
SELECT OBJECT_NAME(c.object_id) as table_name
    , c.name
    , t.name
    , c.precision
    , c.scale
FROM sys.columns c
    INNER JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE t.name IN (&#039;decimal&#039;,&#039;numeric&#039;,&#039;money&#039;)
AND c.scale &lt;&gt; 0
ORDER BY 1, 2
</pre>
<p>The second script lists all of the columns of a specific name with their table and data type information.</p>
<pre class="brush: sql; ">
SELECT OBJECT_NAME(c.object_id) as table_name
    , c.name
    , t.name
    , c.precision
    , c.scale
FROM sys.columns c
    INNER JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE c.name = &#039;ListPrice&#039;
ORDER BY 1, 2
</pre>
<p>Through the use of these and similar scripts, columns and the tables that they are in can be easily determined.  And this information can be found using either the data type or the name of the column.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/find-tables-with-forwarded-records/' rel='bookmark' title='Permanent Link: Find Tables with Forwarded Records'>Find Tables with Forwarded Records</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/08/find-tables-and-columns-by-data-type/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webcast Today &#8211; Using XML to Query Execution Plans</title>
		<link>http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 14:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/</guid>
		<description><![CDATA[I’ll be speaking for the SQL PASS Database Administration Virtual Chapter today at 12 PM Eastern time.  The topic will be Using XML to Query Execution Plans.  The abstract for the event is the following:
SQL Server stores its execution plans as XML in dynamic management views. The execution plans are a gold mine of information. [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-today-using-xml-to-query-execution-plans%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-today-using-xml-to-query-execution-plans%2F" height="61" width="51" /></a></div><p>I’ll be speaking for the <a href="http://www.sqlpass.org/">SQL PASS</a> <a href="http://dba.sqlpass.org/">Database Administration Virtual Chapter</a> today at 12 PM Eastern time.  The topic will be <a href="http://www.sqlpass.org/Events/ctl/ViewEvent/mid/521.aspx?ID=434">Using XML to Query Execution Plans</a>.  The abstract for the event is the following:</p>
<blockquote><p>SQL Server stores its execution plans as XML in dynamic management views. The execution plans are a gold mine of information. From the whether or not the execution plan will rely on parallelism to what columns are requiring a key lookup after a non-clustered index seek. Through a the use of XML this information can be available at your fingertips to help determine the value and impact of an index and guide you in improving the performance of your SQL Server databases. In this session we&#8217;ll look at how you can begin to understand and query the structure of the execution plans in the procedure cache. Also, we&#8217;ll review how to uncover some potential performance issues that may be lurking in your SQL Server.</p></blockquote>
<p>You can get to the event <a href="http://www.sqlpass.org/Events/ctl/ViewEvent/mid/521.aspx?ID=434">here</a>.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webcast Next Week &#8211; Using XML to Query Execution Plans</title>
		<link>http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 14:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/</guid>
		<description><![CDATA[I’ll be speaking for the SQL PASS Database Administration Virtual Chapter next week.  It’ll be on July 28 at 12 PM Eastern time.  The topic will be Using XML to Query Execution Plans.  The abstract for the event is the following:
SQL Server stores its execution plans as XML in dynamic management views. The execution plans [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Using XML to Query Execution Plans'>Webcast Today &#8211; Using XML to Query Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-next-week-using-xml-to-query-execution-plans%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-next-week-using-xml-to-query-execution-plans%2F" height="61" width="51" /></a></div><p>I’ll be speaking for the <a href="http://www.sqlpass.org/">SQL PASS</a> <a href="http://dba.sqlpass.org/">Database Administration Virtual Chapter</a> next week.  It’ll be on July 28 at 12 PM Eastern time.  The topic will be <a href="http://www.sqlpass.org/Events/ctl/ViewEvent/mid/521.aspx?ID=434">Using XML to Query Execution Plans</a>.  The abstract for the event is the following:</p>
<blockquote><p>SQL Server stores its execution plans as XML in dynamic management views. The execution plans are a gold mine of information. From the whether or not the execution plan will rely on parallelism to what columns are requiring a key lookup after a non-clustered index seek. Through a the use of XML this information can be available at your fingertips to help determine the value and impact of an index and guide you in improving the performance of your SQL Server databases. In this session we&#8217;ll look at how you can begin to understand and query the structure of the execution plans in the procedure cache. Also, we&#8217;ll review how to uncover some potential performance issues that may be lurking in your SQL Server.</p></blockquote>
<p>If you register for the event ahead of time you will be entered into a drawing brought to us from CA, our event sponsor.  You can get to the event <a href="http://www.sqlpass.org/Events/ctl/ViewEvent/mid/521.aspx?ID=434">here</a>.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Using XML to Query Execution Plans'>Webcast Today &#8211; Using XML to Query Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webcast Today &#8211; Performance Impacts Related to Different Function Types</title>
		<link>http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 14:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/</guid>
		<description><![CDATA[I’ll be speaking for the SQL PASS Performance Virtual Chapter later today starting at 12 PM Eastern time.  The topic will be Performance Impacts Related to Different Function Types.  The abstract for the event is the following:
User defined functions provide a means to encapsulate business logic in the database tier.  Often the purpose of the [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/sswug-spring-10-ultimate-virtual-conference/' rel='bookmark' title='Permanent Link: SSWUG Spring &#8216;10 Ultimate Virtual Conference'>SSWUG Spring &#8216;10 Ultimate Virtual Conference</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-today-performance-impacts-related-to-different-function-types%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F07%2Fwebcast-today-performance-impacts-related-to-different-function-types%2F" height="61" width="51" /></a></div><p>I’ll be speaking for the <a href="http://www.sqlpass.org/">SQL PASS</a> <a href="http://performance.sqlpass.org/">Performance Virtual Chapter</a> later today starting at 12 PM Eastern time.  The topic will be <a href="https://www323.livemeeting.com/cc/usergroups/join?id=3CF2HR&amp;role=attend&amp;pw=S`w-~7\6b">Performance Impacts Related to Different Function Types</a>.  The abstract for the event is the following:</p>
<blockquote><p>User defined functions provide a means to encapsulate business logic in the database tier.  Often the purpose of the encapsulation is to provide standard method access segments of data within the database.  Unfortunately, not all methods of creating user defined functions are equal.  In this session we’ll review the types of user defined functions and investigate the performance impact in selecting the different types</p>
<p><strong>Goals:</strong></p>
<ul>
<li>Identify purposes for creating user defined functions</li>
<li>Discuss the types of user-defined functions</li>
<li>Demonstrate performance impact in selecting different types of functions</li>
</ul>
</blockquote>
<p>You can get to the event <a href="https://www323.livemeeting.com/cc/usergroups/join?id=3CF2HR&amp;role=attend&amp;pw=S`w-~7\6b">here</a>.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Performance Impacts Related to Different Function Types'>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/sswug-spring-10-ultimate-virtual-conference/' rel='bookmark' title='Permanent Link: SSWUG Spring &#8216;10 Ultimate Virtual Conference'>SSWUG Spring &#8216;10 Ultimate Virtual Conference</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webcast Next Week &#8211; Performance Impacts Related to Different Function Types</title>
		<link>http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 17:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/</guid>
		<description><![CDATA[I’ll be speaking for the SQL PASS Performance Virtual Chapter next week.&#160; It’ll be on July 6 at 12 PM Eastern time.&#160; The topic will be Performance Impacts Related to Different Function Types.&#160; The abstract for the event is the following: 
User defined functions provide a means to encapsulate business logic in the database tier.&#160; [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/sswug-spring-10-ultimate-virtual-conference/' rel='bookmark' title='Permanent Link: SSWUG Spring &#8216;10 Ultimate Virtual Conference'>SSWUG Spring &#8216;10 Ultimate Virtual Conference</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Fwebcast-next-week-performance-impacts-related-to-different-function-types%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Fwebcast-next-week-performance-impacts-related-to-different-function-types%2F" height="61" width="51" /></a></div><p>I’ll be speaking for the <a href="http://www.sqlpass.org/">SQL PASS</a> <a href="http://performance.sqlpass.org/">Performance Virtual Chapter</a> next week.&#160; It’ll be on July 6 at 12 PM Eastern time.&#160; The topic will be Performance Impacts Related to Different Function Types.&#160; The abstract for the event is the following: </p>
<blockquote><p>User defined functions provide a means to encapsulate business logic in the database tier.&#160; Often the purpose of the encapsulation is to provide standard method access segments of data within the database.&#160; Unfortunately, not all methods of creating user defined functions are equal.&#160; In this session we’ll review the types of user defined functions and investigate the performance impact in selecting the different types</p>
<p><strong>Goals:</strong></p>
<ul>
<li>Identify purposes for creating user defined functions </li>
<li>Discuss the types of user-defined functions </li>
<li>Demonstrate performance impact in selecting different types of functions </li>
</ul>
</blockquote>
<p>You can get to the event <a href="https://www323.livemeeting.com/cc/usergroups/join?id=3CF2HR&amp;role=attend&amp;pw=S`w-~7\6b">here</a>.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-today-performance-impacts-related-to-different-function-types/' rel='bookmark' title='Permanent Link: Webcast Today &#8211; Performance Impacts Related to Different Function Types'>Webcast Today &#8211; Performance Impacts Related to Different Function Types</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/sswug-spring-10-ultimate-virtual-conference/' rel='bookmark' title='Permanent Link: SSWUG Spring &#8216;10 Ultimate Virtual Conference'>SSWUG Spring &#8216;10 Ultimate Virtual Conference</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/07/webcast-next-week-using-xml-to-query-execution-plans/' rel='bookmark' title='Permanent Link: Webcast Next Week &#8211; Using XML to Query Execution Plans'>Webcast Next Week &#8211; Using XML to Query Execution Plans</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/06/webcast-next-week-performance-impacts-related-to-different-function-types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Do You Patch SQL Server Regularily?</title>
		<link>http://www.jasonstrate.com/index.php/2010/06/do-you-patch-sql-server-regularily/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/06/do-you-patch-sql-server-regularily/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 18:00:29 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/?p=489</guid>
		<description><![CDATA[Microsoft has released a few new Cumulaive Update for SQL Server. There is an update for each of the supported releases of SQL Server:

Cumulative update package 10 for SQL Server 2005 Service Pack 3
Cumulative update package 8 for SQL Server 2008 Service Pack 1
Cumulative Update package 2 for SQL Server 2008 R2

Cumulative Updates are primarily [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2008/11/cumulative-update-package-2-for-sql-server-2008/' rel='bookmark' title='Permanent Link: Cumulative update package 2 for SQL Server 2008'>Cumulative update package 2 for SQL Server 2008</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/apply-those-updates/' rel='bookmark' title='Permanent Link: Apply Those Updates'>Apply Those Updates</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2008/09/sql-server-2008-cumulative-update-1/' rel='bookmark' title='Permanent Link: SQL Server 2008 Cumulative Update 1'>SQL Server 2008 Cumulative Update 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Fdo-you-patch-sql-server-regularily%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Fdo-you-patch-sql-server-regularily%2F" height="61" width="51" /></a></div><p><a title="The 8-Ball" href="http://www.flickr.com/photos/lleite/85521150/"><img style="margin: 0px 0px 5px 5px; display: inline;" src="http://farm1.static.flickr.com/37/85521150_869f74a525.jpg" border="0" alt="Lego Deadlock" width="199" height="132" align="right" /></a>Microsoft has released a few new Cumulaive Update for SQL Server. There is an update for each of the supported releases of SQL Server:</p>
<ul>
<li><a href="http://support.microsoft.com/kb/983329/en-us">Cumulative update package 10 for SQL Server 2005 Service Pack 3</a></li>
<li><a href="http://support.microsoft.com/kb/981702/en-us">Cumulative update package 8 for SQL Server 2008 Service Pack 1</a></li>
<li><a href="http://support.microsoft.com/kb/2072493/en-us">Cumulative Update package 2 for SQL Server 2008 R2</a></li>
</ul>
<p>Cumulative Updates are primarily intended for SQL Server environments where the issues being resovled are being realized. Though if you are using the components updated by the Cumulative Update it would be good to apply the update.</p>
<p>Unless, of course, you&#8217;d rather spend the weekend behind an 8-Ball troubleshooting and resolving an issue that the Cumulative Update would have prevented. The 8-Ball might be a black and blue ball by Monday when you explain to your manager that the issue was completely avoidable.</p>
<h2>Patch Regularily</h2>
<p>If you aren&#8217;t aware, Microsoft has an <a href="http://support.microsoft.com/kb/935897">Incremental Servicing Model</a>. This model provides guidance on what you should expect from Microsoft from a support standpoint for issues with their products. As part of the Incremental Servicing Model, Microsoft is committed to releasing Cumulative Updates every 2 months.</p>
<p>All fine and dandy but what does that have to do with you? Or if today still feels like Monday&#8230; So what?</p>
<p>The benefit of this model is that it allows us as administrators of SQL Server to develop a plan to regularily download and install the updates. This plan would, of course, include a process to install the updates in the development and test environments. And, also, detail what the steps are for testing and releasing these updates.</p>
<h2>But That&#8217;s Not All</h2>
<p>Just like practicing your database recovery plan. You do practice this, right? Regularily updating your SQL Server environment provides an opportunity to become familiar with this task. This is a critical skill that every DBA should want to have.</p>
<p>If you are well versed in a simple Cumulative Update deployment you have skill and knowledge that will be critical in other situations. When a hotfix needs to be deployed, you will already know your systems well enough to understand the collateral impact of the deployment. If you suddenly inherit a SQL Serve that hasn&#8217;t been maintained since an RTM install, you know what level of patching to place on the server and already have a process in place to get the job done.</p>
<p>Regular updates of your SQL Server environment also gives you the opportunity to read the Cumulative Update notes. You will know what wasn&#8217;t working and become an expert on problems that may exist in your environment. I&#8217;d rather say, &#8220;There is a fix to that issue already in progress. It&#8217;s in the Test environment already.&#8221; Than have to come back and say, &#8220;Microsoft fixed that in an update 6 months ago, I&#8217;ll see what we need to do to get the update deployed.&#8221;</p>
<p>There are likey countless other reasons to take the time to build a process and skillset around regular patching. The long and the short of it is that it is good for you, good for your company, and the responsible thing to do.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2008/11/cumulative-update-package-2-for-sql-server-2008/' rel='bookmark' title='Permanent Link: Cumulative update package 2 for SQL Server 2008'>Cumulative update package 2 for SQL Server 2008</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/apply-those-updates/' rel='bookmark' title='Permanent Link: Apply Those Updates'>Apply Those Updates</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2008/09/sql-server-2008-cumulative-update-1/' rel='bookmark' title='Permanent Link: SQL Server 2008 Cumulative Update 1'>SQL Server 2008 Cumulative Update 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/06/do-you-patch-sql-server-regularily/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Index Those Foreign Keys</title>
		<link>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 21:00:59 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Deadlocks]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[Indexing]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/?p=486</guid>
		<description><![CDATA[Today started with some quality time getting to know a deadlock that had occurred. While working through the deadlock, I noticed that there were a number of foreign key relationships that weren&#8217;t indexed on the parent side of the relationship.
I am going to skip over the why to index foreign keys and save that for [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/gotta-stop-violating-foreign-keys/' rel='bookmark' title='Permanent Link: Gotta Stop Violating Foreign Keys'>Gotta Stop Violating Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/02/change-trusted-state-of-foreign-keys/' rel='bookmark' title='Permanent Link: Change Trusted State of Foreign Keys'>Change Trusted State of Foreign Keys</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Findex-those-foreign-keys%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F06%2Findex-those-foreign-keys%2F" height="61" width="51" /></a></div><p><a title="Lego Deadlock" href="http://www.flickr.com/photos/oskay/265879129/"><img style="margin: 0px 0px 5px 5px; display: inline;" src="http://farm1.static.flickr.com/119/265879129_2b6b17edf2.jpg" border="0" alt="Lego Deadlock" width="199" height="132" align="right" /></a>Today started with some quality time getting to know a deadlock that had occurred. While working through the deadlock, I noticed that there were a number of foreign key relationships that weren&#8217;t indexed on the parent side of the relationship.</p>
<p>I am going to skip over the why to index foreign keys and save that for a later point when I have more time to go through it with some really pretty pictures. Today though, I want to share the scripts that I put together to look for these situations and help prevent issues related to them.</p>
<h2>Brute Force Indexing</h2>
<p>This first script is a brute force attack on this need. If you set the output for text results in SQL Server Management Studio (SSMS) you&#8217;ll get a script with all of the indexes you&#8217;ll need to cover all of your foreign key relationships.</p>
<pre class="brush: sql; ">

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON

;WITH cIndexes
AS (
SELECT i.object_id
,i.name
,(SELECT QUOTENAME(ic.column_id,&#039;(&#039;)
FROM sys.index_columns ic
WHERE i.object_id = ic.object_id
AND i.index_id = ic.index_id
AND is_included_column = 0
ORDER BY key_ordinal ASC
FOR XML PATH(&#039;&#039;)) AS indexed_compare
FROM sys.indexes i
), cForeignKeys
AS (
SELECT fk.name AS foreign_key_name
,&#039;PARENT&#039; as foreign_key_type
,fkc.parent_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.parent_object_id = c.object_id AND ifkc.parent_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.parent_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
UNION ALL
SELECT fk.name AS foreign_key_name
,&#039;REFERENCED&#039; as foreign_key_type
,fkc.referenced_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.referenced_object_id = c.object_id AND ifkc.referenced_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.referenced_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
), cRowCount
AS (
SELECT object_id
,SUM(row_count) AS row_count
FROM sys.dm_db_partition_stats ps
WHERE index_id IN (1,0)
GROUP BY object_id
)
SELECT
&#039;--Missing foreign key index for &#039;+fk.foreign_key_name+CHAR(13)+CHAR(10)+&#039;GO&#039;+CHAR(13)+CHAR(10)+
+&#039;CREATE NONCLUSTERED INDEX FKIX_&#039;+OBJECT_NAME(fk.object_id)+&#039;_&#039;+REPLACE(REPLACE(REPLACE(REPLACE(fk.fk_columns,&#039;,&#039;,&#039;&#039;),&#039;[&#039;,&#039;&#039;),&#039;]&#039;,&#039;&#039;),&#039; &#039;,&#039;&#039;)
+CHAR(13)+CHAR(10)+
+&#039;ON [dbo].[&#039;+OBJECT_NAME(fk.object_id)+&#039;] (&#039;+fk.fk_columns+&#039;)&#039;+CHAR(13)+CHAR(10)+
+&#039;GO&#039;+CHAR(13)+CHAR(10)+CHAR(13)+CHAR(10)
FROM cForeignKeys fk
INNER JOIN cRowCount rc ON fk.object_id = rc.object_id
LEFT OUTER JOIN cIndexes i ON fk.object_id = i.object_id AND i.indexed_compare LIKE fk.fk_columns_compare + &#039;%&#039;
WHERE i.name IS NULL
ORDER BY OBJECT_NAME(fk.object_id), fk.fk_columns
</pre>
<h2>Foreign Key Monitoring</h2>
<p>This second script accommodates for those situations when you may not want to just index every foreign key that is out there. Maybe there&#8217;s a really old table in the database with a foreign key relationship that just doesn&#8217;t matter any more. Is it worth indexing along a vector that won&#8217;t lead to any performance impact &#8211; either negative or positive? Most likely not.</p>
<p>For this script, the results output a list of foreign keys relationships that are not fully indexed. Included in the result script is a column with XML data in it that contains a script for creating an index. You may notice that the format for this is very similar to the schema created when outputtingmmissing Indexes from execution plans.</p>
<pre class="brush: sql; ">

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

;WITH cIndexes
AS (
SELECT i.object_id
,i.name
,(SELECT QUOTENAME(ic.column_id,&#039;(&#039;)
FROM sys.index_columns ic
WHERE i.object_id = ic.object_id
AND i.index_id = ic.index_id
AND is_included_column = 0
ORDER BY key_ordinal ASC
FOR XML PATH(&#039;&#039;)) AS indexed_compare
FROM sys.indexes i
), cForeignKeys
AS (
SELECT fk.name AS foreign_key_name
,&#039;PARENT&#039; as foreign_key_type
,fkc.parent_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.parent_object_id = c.object_id AND ifkc.parent_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.parent_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
UNION ALL
SELECT fk.name AS foreign_key_name
,&#039;REFERENCED&#039; as foreign_key_type
,fkc.referenced_object_id AS object_id
,STUFF((SELECT &#039;, &#039; + QUOTENAME(c.name)
FROM sys.foreign_key_columns ifkc
INNER JOIN sys.columns c ON ifkc.referenced_object_id = c.object_id AND ifkc.referenced_column_id = c.column_id
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)), 1, 2, &#039;&#039;) AS fk_columns
,(SELECT QUOTENAME(ifkc.referenced_column_id,&#039;(&#039;)
FROM sys.foreign_key_columns ifkc
WHERE fk.object_id = ifkc.constraint_object_id
ORDER BY ifkc.constraint_column_id
FOR XML PATH(&#039;&#039;)) AS fk_columns_compare
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
WHERE fkc.constraint_column_id = 1
), cRowCount
AS (
SELECT object_id
,SUM(row_count) AS row_count
FROM sys.dm_db_partition_stats ps
WHERE index_id IN (1,0)
GROUP BY object_id
)
SELECT
fk.foreign_key_name
,OBJECT_NAME(fk.object_id) AS fk_table_name
,fk.fk_columns
,rc.row_count AS row_count
,CAST(&#039;&lt;!--dex  &#039;+CHAR(13)+CHAR(10)+&#039;Missing foreign key index for &#039;+fk.foreign_key_name+CHAR(13)+CHAR(10)+CHAR(13)+CHAR(10)+&#039;USE [&#039;+DB_NAME()+&#039;]&#039;&lt;br--&gt; +CHAR(13)+CHAR(10)+&#039;GO&#039;+CHAR(13)+CHAR(10)+
+&#039;CREATE NONCLUSTERED INDEX []&#039;+CHAR(13)+CHAR(10)+
+&#039;ON [dbo].[&#039;+OBJECT_NAME(fk.object_id)+&#039;] (&#039;+fk.fk_columns+&#039;)&#039;+CHAR(13)+CHAR(10)+
+&#039;GO&#039;+CHAR(13)+CHAR(10)+&#039;--?&gt;&#039; AS xml) foreign_key_index_schema
FROM cForeignKeys fk
INNER JOIN cRowCount rc ON fk.object_id = rc.object_id
LEFT OUTER JOIN cIndexes i ON fk.object_id = i.object_id AND i.indexed_compare LIKE fk.fk_columns_compare + &#039;%&#039;
WHERE i.name IS NULL
ORDER BY OBJECT_NAME(fk.object_id), fk.fk_columns
</pre>
<h2>Closing Up</h2>
<p>The DDL schema output in these scripts is very basic. It doesn&#8217;t account for potentially important things like partitions and filegroups. Obviously, you&#8217;ll need to modify this for your own environment and don&#8217;t just run this on production.</p>
<p>I see a lot of potential in these scripts and am planning to include them as part of preparing for releases when I am clients. A good way to dot the i&#8217;s and cross the t&#8217;s.</p>
<p>Individual results may vary. No Legos were harmed in the writing on this post.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/07/gotta-stop-violating-foreign-keys/' rel='bookmark' title='Permanent Link: Gotta Stop Violating Foreign Keys'>Gotta Stop Violating Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/02/change-trusted-state-of-foreign-keys/' rel='bookmark' title='Permanent Link: Change Trusted State of Foreign Keys'>Change Trusted State of Foreign Keys</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Doing Something About Auto Generated Names</title>
		<link>http://www.jasonstrate.com/index.php/2010/05/doing-something-about-auto-generated-names/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/05/doing-something-about-auto-generated-names/#comments</comments>
		<pubDate>Wed, 26 May 2010 17:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/05/doing-something-about-auto-generated-names/</guid>
		<description><![CDATA[I like my name.  It provides a point of reference to who I am.  If I am at work and someone calls for “Jason Strate”… that’s me.  If I am at home, the same thing can happen and I still know that it’s me.  I know that no matter where I am, my name will [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/find-tables-with-forwarded-records/' rel='bookmark' title='Permanent Link: Find Tables with Forwarded Records'>Find Tables with Forwarded Records</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fdoing-something-about-auto-generated-names%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fdoing-something-about-auto-generated-names%2F" height="61" width="51" /></a></div><p><a title="Zombie Apocafest 2009 - Shaun &amp; Ed" href="http://www.flickr.com/photos/12426416@N00/3982315713/"><img style="margin: 0px 0px 5px 5px; display: inline;" src="http://static.flickr.com/2668/3982315713_fb262e22e1.jpg" border="0" alt="Zombie Apocafest 2009 - Shaun &amp; Ed" width="199" height="132" align="right" /></a>I like my name.  It provides a point of reference to who I am.  If I am at work and someone calls for “Jason Strate”… that’s me.  If I am at home, the same thing can happen and I still know that it’s me.  I know that no matter where I am, my name will be a constant and it means something when it is called.  <span style="text-decoration: line-through;">Hopefully, it doesn’t mean “late to dinner”.</span></p>
<p>This same principle applies to the tables and the objects related to those tables.  We give that table a name in the development environment, maybe it’s called “ZombieBaconUnicorn”.  We expect that it will be called “ZombieBaconUnicorn”.  Unfortunately, this doesn’t always ring true with other database objects related to tables; such as Primary Keys and Defaults Constraints.</p>
<h2>Random Naming</h2>
<p>There are multiple ways to create Primary Key and Default Constraints and they don’t all have an implied name.  Take for instance the following script, what would you assume the names of the Primary Key and Default Constraints would be?</p>
<pre class="brush: sql; ">
CREATE TABLE dbo.RandomPKandDC
(
RandomPKandDCID int IDENTITY(1,1) PRIMARY KEY CLUSTERED
,Column1 datetime DEFAULT(GETDATE())
)

SELECT name FROM sys.objects
WHERE parent_object_id = OBJECT_ID(&#039;dbo.RandomPKandDC&#039;)
</pre>
<p>Did you guess the following names?</p>
<p><a href="http://www.jasonstrate.com/wp-content/uploads/2010/05/image.png"><img style="display: inline; border: 0px;" title="image" src="http://www.jasonstrate.com/wp-content/uploads/2010/05/image_thumb.png" border="0" alt="image" width="242" height="62" /></a></p>
<p>No?!  Run it on you machine, you’ll get your own unique names.</p>
<h2>Non-Random Naming</h2>
<p>Getting around the random naming is pretty simple.  Below I’ll would you through the steps.</p>
<p>The first change is how you’ll define the PRIMARY KEY on the table with the <a href="http://msdn.microsoft.com/en-us/library/ms174979.aspx">CREATE TABLE</a> statement.  Instead of adding PRIMARY KEY CLUSTERED on the column definition, add it to the table as a constraint.</p>
<pre class="brush: sql; ">
CREATE TABLE dbo.NonRandomPKandDC
(
NonRandomPKandDCID int IDENTITY(1,1)
,Column1 datetime
,CONSTRAINT PK_NonRandomPKandDC_RandomPKandDCID PRIMARY KEY CLUSTERED (NonRandomPKandDCID)
)
</pre>
<p>Next you want to use the ALTER TABLE statement to add the DEFAULT CONSTRAINT.  Instead of making the default part of the column definition in the CREATE TABLE, you want to name the default as a constraint to name it as it is created.</p>
<pre class="brush: sql; ">
ALTER TABLE dbo.NonRandomPKandDC ADD CONSTRAINT DF_NonRandomPKandDC_Column1
DEFAULT (getdate()) FOR [Column1]
</pre>
<p>Take a look at the results of the next query:</p>
<pre class="brush: sql; ">
SELECT name FROM sys.objects
WHERE parent_object_id = OBJECT_ID(&#039;dbo.NonRandomPKandDC&#039;)
</pre>
<p><a href="http://www.jasonstrate.com/wp-content/uploads/2010/05/image1.png"><img style="display: inline; border: 0px;" title="image" src="http://www.jasonstrate.com/wp-content/uploads/2010/05/image_thumb1.png" border="0" alt="image" width="270" height="59" /></a></p>
<p>On your server and mine the objects will have the same name.  When you deploy objects build from T-SQL like this from development to test to production they will have the same names.</p>
<h2>What the!?</h2>
<p>Now there isn’t anything wrong with these random names from the perspective of how your database will perform.  But it will hose up things such as database comparisons and investigating errors.</p>
<p>With database comparisons, the issue is pretty obvious.  If the contents of the object are the same but the name is different then it isn’t the exact same object.  Many tools have options for ignoring these names, but there are some that don’t.  Even when the tool has the option to ignore, you will need to rely on the operator of the tool to disable the feature.</p>
<p>Looking now at investigating errors, I am a big fan of errors that can tell me the problem within the database.  Which of the following is easier to understand.  The first with the random name:</p>
<blockquote><p>Msg 2627, Level 14, State 1, Line 2<br />
Violation of PRIMARY KEY constraint &#8216;PK__RandomPKandDC__5D60DB10&#8242;. Cannot insert duplicate key in object &#8216;dbo.RandomPKandDC&#8217;.<br />
The statement has been terminated.</p></blockquote>
<p>Or the second with the stated name:</p>
<blockquote><p>Msg 2627, Level 14, State 1, Line 2<br />
Violation of PRIMARY KEY constraint &#8216;PK_NonRandomPKandDC_RandomPKandDCID&#8217;. Cannot insert duplicate key in object &#8216;dbo.NonRandomPKandDC&#8217;.<br />
The statement has been terminated.</p></blockquote>
<p>Ok, maybe this isn’t the best example of this type of issue, but it does tell me exactly the issue and because I named the object explicitly I know where the problem is and something about the issue before digging into the schema of the table.</p>
<p>Overall, this is about reducing pain points in building and using your databases.  The easier it is to manage them once they are deployed, the more Bejeweled Blitz you can play on <a href="http://www.facebook.com/StrateSQL">Facebook</a> between your projects.</p>
<h2>Renaming the Objects</h2>
<p>Maybe I’ve sold you on this idea.  If so, you may be thinking “What the heck do you do with all of my existing databases objects?”  That answer is simple… rename them.  Since the names of these objects isn’t tied to how they are defined, you can easily get them renamed with <a href="http://msdn.microsoft.com/en-us/library/ms188351.aspx">sp_rename</a>.</p>
<p>The following two scripts are what I use to rename PRIMARY KEY CONSTRAINTS and DEFAULT CONSTRAINTS.</p>
<p>This first one will provide sp_rename statements that you can execute to rename all of your PRIMARY KEY CONSTRAINTS:</p>
<pre class="brush: sql; ">
;WITH PKNames
AS (
SELECT name AS IndexName
,OBJECT_NAME(object_id) AS TableName
,OBJECT_SCHEMA_NAME(object_id) as SchemaName
,(SELECT &#039;&#039; + c.name
FROM sys.index_columns ic
INNER JOIN sys.columns c
ON ic.object_id = c.object_id
AND ic.index_column_id = c.column_id
WHERE ic.object_id = i.object_id
AND ic.index_id = i.index_id
AND ic.is_included_column = 0
ORDER BY ic.key_ordinal
FOR XML PATH(&#039;&#039;)) AS Columns
FROM sys.indexes i
WHERE i.is_primary_key = 1
)
SELECT &#039;EXEC sp_rename &#039;&#039;&#039; + QUOTENAME(SchemaName) + &#039;.&#039; + QUOTENAME(IndexName) + &#039;&#039;&#039;, &#039;&#039;PK_&#039; + TableName + &#039;_&#039; + Columns + &#039;&#039;&#039;&#039;
FROM PKNames
WHERE IndexName &lt;&gt; &#039;PK_&#039; + TableName + &#039;_&#039; + Columns
</pre>
<p>The second one will provide sp_rename statements that you can execute to rename all of your DEFAULT CONSTRAINTS:</p>
<pre class="brush: sql; ">
SELECT &#039;EXEC sp_rename &#039;&#039;&#039; + QUOTENAME(OBJECT_SCHEMA_NAME(dc.parent_object_id)) + &#039;.&#039;
+ QUOTENAME(dc.name) + &#039;&#039;&#039;, &#039;&#039;DF_&#039; + OBJECT_NAME(dc.parent_object_id) + &#039;_&#039; + c.name + &#039;&#039;&#039;&#039;
FROM sys.default_constraints dc
INNER JOIN sys.columns c ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id
WHERE dc.name &lt;&gt; &#039;DF_&#039; + OBJECT_NAME(dc.parent_object_id) + &#039;_&#039; + c.name
</pre>
<p>Hopefully these can be helpful for you as well.</p>
<h2>Conclusion</h2>
<p>In a roundabout way, this post has been about naming conventions.  Make the world a prettier place by having a convention on naming the objects in your database.</p>
<p>Last word… don’t just run out and use this in your production database without doing your own testing and promoting using your own company’s deployment process.  An obvious statement but one that I thought I should point out since I know how tempting this can be.</p>
<p>EDIT 2010/05/27: Modified scripts to account for schema variations.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2010/06/index-those-foreign-keys/' rel='bookmark' title='Permanent Link: Index Those Foreign Keys'>Index Those Foreign Keys</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2010/03/find-tables-with-forwarded-records/' rel='bookmark' title='Permanent Link: Find Tables with Forwarded Records'>Find Tables with Forwarded Records</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/01/find-duplicate-foreign-keys/' rel='bookmark' title='Permanent Link: Find Duplicate Foreign Keys'>Find Duplicate Foreign Keys</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/05/doing-something-about-auto-generated-names/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Connect Item on Import/Export Wizard</title>
		<link>http://www.jasonstrate.com/index.php/2010/05/connect-item-on-importexport-wizard/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/05/connect-item-on-importexport-wizard/#comments</comments>
		<pubDate>Thu, 20 May 2010 19:41:06 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Connect]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/?p=456</guid>
		<description><![CDATA[I like using raw files in SQL Server Integration Services (SSIS).  They are a quick way to build data repository that will be used else where in a package or for use with a separate package.  In a recent project, raw files were used to move client data around in a new import process that consolidated business logic [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2006/02/sql-server-2005-script-wizard/' rel='bookmark' title='Permanent Link: SQL Server 2005 Script Wizard'>SQL Server 2005 Script Wizard</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/06/this-wednesday-itcare-event-solving-business-pains-with-sql-server-integration-services/' rel='bookmark' title='Permanent Link: This Wednesday ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services'>This Wednesday ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/06/june-itcare-event-solving-business-pains-with-sql-server-integration-services/' rel='bookmark' title='Permanent Link: June ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services'>June ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fconnect-item-on-importexport-wizard%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fconnect-item-on-importexport-wizard%2F" height="61" width="51" /></a></div><p><a href="http://www.jasonstrate.com/wp-content/uploads/2010/05/5-20-2010-1-56-43-PM.jpg"></a>I like using raw files in SQL Server Integration Services (SSIS).  They are a quick way to build data repository that will be used else where in a package or for use with a separate package.  In a recent project, raw files were used to move client data around in a new import process that consolidated business logic and improved performance. </p>
<p>As much as I like raw files, there is a place in SQL Server where the love I have for raw files is lacking.  This is with the Import/Export Wizard in Management Studio.  If you look through the wizard, you&#8217;ll find Excel love, Access love, and even some Oracle love.  But there isn&#8217;t an option to import or export raw file data.</p>
<p> <a href="http://www.jasonstrate.com/wp-content/uploads/2010/05/5-20-2010-1-56-43-PM.jpg"><img title="Import / Export Wizard Data" src="http://www.jasonstrate.com/wp-content/uploads/2010/05/5-20-2010-1-56-43-PM-300x160.jpg" alt="" width="300" height="160" /></a></p>
<h2>Stop the Madness</h2>
<p><a href="http://en.wikipedia.org/wiki/Susan_Powter">Susan Powter</a> said it best, &#8220;Stop the Madness&#8221;.  Ok, maybe this isn&#8217;t madness.  But it sure is irritating when I have to write an SSIS package from scratch to import a raw file to my sandbox database to see what data is in it that is causing issues.  If it were any other data source or destination, there wouldn&#8217;t be a need to do that extra work.</p>
<p>Is this extra work very hard?  No, of course not.  But this is a barrier to using this format.  I&#8217;ve been pushed away from them before when explaining the need to build a package to view raw file data.  When other formats can be imported with just a few clicks of a button.  The five to ten minutes to stop and build the package and import the data can add up in some situations.  And compating it to the minute or so to use the wizard, this can be a significant time savings when developing and testing SSIS packages.</p>
<p>There is certainly no sense in complaining without trying to fix.  So here it goes&#8230;</p>
<p>If you think this idea is kicking, special, or worthy of your support &#8211; please go out and <a href="https://connect.microsoft.com/SQLServer/feedback/details/560470/ssis-add-raw-file-data-source-to-import-export-wizard">vote up the Connect item that has been submitted on it</a>.</p>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2006/02/sql-server-2005-script-wizard/' rel='bookmark' title='Permanent Link: SQL Server 2005 Script Wizard'>SQL Server 2005 Script Wizard</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/06/this-wednesday-itcare-event-solving-business-pains-with-sql-server-integration-services/' rel='bookmark' title='Permanent Link: This Wednesday ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services'>This Wednesday ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/06/june-itcare-event-solving-business-pains-with-sql-server-integration-services/' rel='bookmark' title='Permanent Link: June ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services'>June ITCare Event &#8211; Solving Business Pains with SQL Server Integration Services</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/05/connect-item-on-importexport-wizard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Searching for Plans</title>
		<link>http://www.jasonstrate.com/index.php/2010/05/searching-for-plans/</link>
		<comments>http://www.jasonstrate.com/index.php/2010/05/searching-for-plans/#comments</comments>
		<pubDate>Mon, 03 May 2010 22:00:00 +0000</pubDate>
		<dc:creator>jstrate</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[DBADiagnostics]]></category>
		<category><![CDATA[DMO]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQLServerSyndication]]></category>

		<guid isPermaLink="false">http://www.jasonstrate.com/index.php/2010/05/searching-for-plans/</guid>
		<description><![CDATA[
A while back I wrote a post on a procedure I created for the DBADiagnostics database that I talk about from time to time.  This procedure allowed users to search the procedure cache to find plans for procedures by database name and object name.  This had worked out pretty good until I noticed something the [...]


Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/06/really-search-cache-for-execution-plans/' rel='bookmark' title='Permanent Link: Really Search Cache for Execution Plans'>Really Search Cache for Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/01/search-cache-for-execution-plans/' rel='bookmark' title='Permanent Link: Search Cache For Execution Plans'>Search Cache For Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/04/find-query-plans-that-may-utilize-parallelism/' rel='bookmark' title='Permanent Link: Find Query Plans That May Utilize Parallelism'>Find Query Plans That May Utilize Parallelism</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fsearching-for-plans%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.jasonstrate.com%2Findex.php%2F2010%2F05%2Fsearching-for-plans%2F" height="61" width="51" /></a></div><p><a href="http://www.flickr.com/photos/parl/70999185/" target="_blank"><img style="display: inline; border-width: 0px;" title="70999185_58c1ad9d35" src="http://www.jasonstrate.com/images/SearchingforPlans_E97E/70999185_58c1ad9d35.jpg" border="0" alt="70999185_58c1ad9d35" width="165" height="111" align="right" /></a></p>
<p>A while back I wrote a post on a procedure I created for the <a href="http://www.jasonstrate.com/index.php/tag/dbadiagnostics/" target="_blank">DBADiagnostics database</a> that I talk about from time to time.  This <a href="http://www.jasonstrate.com/index.php/2009/06/really-search-cache-for-execution-plans/" target="_blank">procedure allowed users to search the procedure cache to find plans for procedures by database name and object name</a>.  This had worked out pretty good until I noticed something the other day.</p>
<p>The procedure is using the <a href="http://msdn.microsoft.com/en-us/library/ms189741.aspx" target="_blank">sys.dm_exec_query_stats</a> as the based table for the query to build itself upon.  The trouble with using this <a href="http://www.jasonstrate.com/index.php/tag/dmo/" target="_blank">DMV</a> is that it doesn’t have all of the plans listed from the procedure cache.  Only those that currently have stats stored for sql_handles.</p>
<p>About the same time I started writing this post, I noticed a post by Adam Machanic (<a href="http://twitter.com/adammachanic" target="_blank">twitter</a> | <a href="http://sqlblog.com/blogs/adam_machanic/default.aspx" target="_blank">blog</a>) in which he puts out <a href="http://sqlblog.com/blogs/adam_machanic/archive/2010/04/22/a-warning-to-those-using-sys-dm-exec-query-stats.aspx" target="_blank">a warning to those using sys.dm_exec_query_stats</a>.  In that post, he discusses how the ALTER TABLE statement can result in a batch missing this DMV.</p>
<p>Considering all this lends itself to the question, is there a better DMV that can be used to find plans in the procedure cache?</p>
<h2>Use sys.dm_exec_cached_plans Instead</h2>
<p>Another DMV that has this information in it is the DMV <a href="http://msdn.microsoft.com/en-us/library/ms187404.aspx" target="_blank">sys.dm_exec_cached_plans</a>.  This DMV is designed to provide a list of all cached plans in the procedure cache.  To illustrate the difference, lets take a look at the following two queries.</p>
<pre class="brush: sql; ">

SELECT COUNT(DISTINCT plan_handle)
FROM sys.dm_exec_cached_plans
GO 

SELECT COUNT(DISTINCT plan_handle)
FROM sys.dm_exec_query_stats
GO
</pre>
<p>On my system, the following results are returned:</p>
<p><a href="http://www.jasonstrate.com/images/SearchingforPlans_E97E/image.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.jasonstrate.com/images/SearchingforPlans_E97E/image_thumb.png" border="0" alt="image" width="144" height="117" /></a></p>
<p>The first value is the number of plan_handles in sys.dm_exec_cached_plans.  The second is the number of plan_handles in sys.dm_exec_query_stats.  There is a substantial difference between the two.  This is something you’d be expecting based on the information at the start of this post.</p>
<h2>Query to Find Cached Plans</h2>
<p>Now that I’ve outlined the issues with my original post, lets take a look at a script that will query the procedure cache to look for plans stored for stored procedures and other database objects.</p>
<pre class="brush: sql; ">

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
GO

DECLARE @DatabaseName sysname
    ,@ObjectName sysname 

SELECT @DatabaseName = &#039;msdb&#039;
    ,@ObjectName = &#039;sp_jobhistory_row_limiter&#039;;

WITH PlanSearch
AS (
      SELECT qp.dbid
            ,qp.objectid
            ,DB_NAME(qp.dbid) as DatabaseName
            ,OBJECT_NAME(qp.objectid, qp.dbid) as ObjectName
            ,cp.usecounts
            ,cp.plan_handle
      FROM sys.dm_exec_cached_plans cp
            CROSS APPLY sys.dm_exec_text_query_plan(cp.plan_handle, DEFAULT, DEFAULT) qp
    WHERE cp.cacheobjtype = &#039;Compiled Plan&#039;
      AND (DB_NAME(qp.dbid) = @DatabaseName OR NULLIF(@DatabaseName,&#039;&#039;) IS NULL)
    AND (OBJECT_NAME(qp.objectid, qp.dbid) = @ObjectName OR NULLIF(@ObjectName, &#039;&#039;) IS NULL)
)
,PlansAndStats
AS (
      SELECT ps.DatabaseName
        ,ps.ObjectName
        ,ps.usecounts -- Use in place of qs.execution_count for whole plan count
        ,CAST(SUM(qs.total_worker_time)/(ps.usecounts*1.) as decimal(12,2)) AS avg_cpu_time
        ,CAST(SUM(qs.total_logical_reads + qs.total_logical_writes)/(ps.usecounts*1.) as decimal(12,2)) AS avg_io
        ,SUM(qs.total_elapsed_time)/(ps.usecounts)/1000 as avg_elapsed_time_ms
        ,ps.plan_handle
    FROM PlanSearch ps
            LEFT OUTER JOIN sys.dm_exec_query_stats qs ON ps.plan_handle = qs.plan_handle
    GROUP BY ps.DatabaseName
        ,ps.ObjectName
        ,ps.usecounts
            ,ps.plan_handle
)
SELECT ps.DatabaseName
    ,ps.ObjectName
      ,ps.usecounts
      ,ps.avg_cpu_time
      ,ps.avg_io
      ,ps.avg_elapsed_time_ms
      ,qp.query_plan
      ,ps.plan_handle
FROM PlansAndStats ps
      CROSS APPLY sys.dm_exec_query_plan(ps.plan_handle) qp 
</pre>
<p>Executing the script above provides the following output:</p>
<p><a href="http://www.jasonstrate.com/images/SearchingforPlans_E97E/image_3.png"><img style="display: inline; border: 0px;" title="image" src="http://www.jasonstrate.com/images/SearchingforPlans_E97E/image_thumb_3.png" border="0" alt="image" width="557" height="23" /></a></p>
<p>The output includes the name of the object being sought and a link to the plan from the procedure cache.  Included with this is some basic performance information from sys.dm_exec_query_stats that can be useful in determining performance variations between the plans returned.</p>
<h2>Procedure to Find Plans</h2>
<p>For those that like to take these scripts and build stored procedures for them.  I’ve also included a script below that includes this information.</p>
<div id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:e7849190-c137-4aba-a9ee-954dc29c9e08" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<div><a href="http://www.jasonstrate.com/images/SearchingforPlans_E97E/Utility.CachedPlanSearch.txt" target="_self">Utility.CachedPlanSearch.txt</a></div>
</div>


<p>Related posts:<ol><li><a href='http://www.jasonstrate.com/index.php/2009/06/really-search-cache-for-execution-plans/' rel='bookmark' title='Permanent Link: Really Search Cache for Execution Plans'>Really Search Cache for Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/01/search-cache-for-execution-plans/' rel='bookmark' title='Permanent Link: Search Cache For Execution Plans'>Search Cache For Execution Plans</a></li>
<li><a href='http://www.jasonstrate.com/index.php/2009/04/find-query-plans-that-may-utilize-parallelism/' rel='bookmark' title='Permanent Link: Find Query Plans That May Utilize Parallelism'>Find Query Plans That May Utilize Parallelism</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jasonstrate.com/index.php/2010/05/searching-for-plans/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
