<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Louis Davidson : SQL Server</title><link>http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx</link><description>Tags: SQL Server</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Why We Write #1 - An Interview With Thomas LaRock</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2013/03/21/why-we-write-1-an-interview-with-thomas-larock.aspx</link><pubDate>Fri, 22 Mar 2013 00:03:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:48340</guid><dc:creator>drsql</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/48340.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=48340</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=48340</wfw:comment><description>I 've been a writer of trade level technical materials for over 13 years now, writing books, articles, blogs, and even tweets for a variety of outlets, almost exclusively about Microsoft SQL Server. While I won't claim to be the best writer in the world,...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2013/03/21/why-we-write-1-an-interview-with-thomas-larock.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=48340" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQLPASS/default.aspx">SQLPASS</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Why+We+Write/default.aspx">Why We Write</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Writing/default.aspx">Writing</category></item><item><title>Chapter 7–Enforced Data Protection</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2011/06/21/chapter-7-enforced-data-protection.aspx</link><pubDate>Tue, 21 Jun 2011 04:36:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:36380</guid><dc:creator>drsql</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/36380.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=36380</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=36380</wfw:comment><description>As the book progresses, I find myself veering from the original stated outline quite a bit, because as I teach about this more (and I am teaching a daylong db design class in August at http://www.sqlsolstice.com/ … shameless plug, but it is on topic :)...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2011/06/21/chapter-7-enforced-data-protection.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=36380" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Database+Design/default.aspx">Database Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Writing/default.aspx">Writing</category></item><item><title>See you in Columbus Saturday?</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2011/06/06/see-you-in-columbus-saturday.aspx</link><pubDate>Mon, 06 Jun 2011 04:32:45 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:36088</guid><dc:creator>drsql</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/36088.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=36088</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=36088</wfw:comment><description>Assuming all goes as planned, I will be in Columbus, OH this Friday night and Saturday for SQL Saturday 75 . I really love SQL Saturday events the best of all of the events because they are very intimate in nature. As a fairly antisocial person, I sometimes...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2011/06/06/see-you-in-columbus-saturday.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=36088" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Database+Design/default.aspx">Database Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/PASS/default.aspx">PASS</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Saturday/default.aspx">SQL Saturday</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Normalization and How to Know When You Are Done… The short version…</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2011/05/29/normalization-and-how-to-know-when-you-are-done-the-short-version.aspx</link><pubDate>Sun, 29 May 2011 20:54:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35960</guid><dc:creator>drsql</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/35960.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=35960</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=35960</wfw:comment><description>A while back, I was working on a short article about Normalization for a book that never got published (admittedly I wasn’t getting paid for the article, and it wasn’t for charity, so I wasn’t that broken up over it.)&amp;#160; The task at hand was to, in...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2011/05/29/normalization-and-how-to-know-when-you-are-done-the-short-version.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=35960" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Database+Design/default.aspx">Database Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Design/default.aspx">Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Development/default.aspx">Development</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Normalization/default.aspx">Normalization</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Terminology/default.aspx">Terminology</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Writing/default.aspx">Writing</category></item><item><title>Quest DMV Breakfast Code – Disk IO</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2009/11/04/quest-dmv-breakfast-code-disk-io.aspx</link><pubDate>Wed, 04 Nov 2009 17:52:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:18532</guid><dc:creator>drsql</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/18532.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=18532</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=18532</wfw:comment><description>For any of you who attended the Quest breakfast at PASS (and anyone else really) I wanted to go ahead and post the code and give a little wrap up/explanation. (I will post the stuff on perf counters later. They are cool, but this is really what I wanted...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2009/11/04/quest-dmv-breakfast-code-disk-io.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=18532" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Dynamic+Management/default.aspx">Dynamic Management</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/PASS/default.aspx">PASS</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Techniques/default.aspx">SQL Techniques</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Tools/default.aspx">SQL Tools</category></item><item><title>Fifth pillar - Secure</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2009/10/06/fifth-pillar-secure.aspx</link><pubDate>Tue, 06 Oct 2009 23:52:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:17330</guid><dc:creator>drsql</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/17330.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=17330</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=17330</wfw:comment><description>As I have mentioned in all of the previous posts, basic functionality is the foundation of any system. So it goes without saying that if you have just implemented a payroll system, everyone is getting paid.&amp;#160; To meet the basic bar that EVERYONE agrees...(&lt;a href="http://sqlblog.com/blogs/louis_davidson/archive/2009/10/06/fifth-pillar-secure.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=17330" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Database+Design/default.aspx">Database Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Pillars/default.aspx">Pillars</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Security/default.aspx">Security</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Headed..South..To Atlanta for SQL Saturday</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2009/04/23/headed-south-to-atlanta.aspx</link><pubDate>Fri, 24 Apr 2009 02:55:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13489</guid><dc:creator>drsql</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/13489.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=13489</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=13489</wfw:comment><description>&lt;P&gt;Heading down to SQL Saturday (&lt;A href="http://www.sqlsaturday.com/"&gt;www.sqlsaturday.com&lt;/A&gt;) in Atlanta to give a 9:15 AM session on Database Design, with a greater than normal dose of normal thrown in. I hope there are more than 7 people to show up, because I would hate if everyone got some swag (I usually like tossing out stuff when people make cool and interesting statements, and NOT when they prove me wrong…you know who (all) you are :). Apparently they were at their capacity, so maybe not.&amp;nbsp; If you need to know where it is, check here: &lt;A title=http://www.sqlsaturday.com/eventhome.aspx?eventid=17 href="http://www.sqlsaturday.com/eventhome.aspx?eventid=17"&gt;http://www.sqlsaturday.com/eventhome.aspx?eventid=17&lt;/A&gt;, and come on out.&amp;nbsp; The more smart alecky know-it-alls I get who want to prove me wrong the better…well, as long as you sit there quietly and learn something…&lt;/P&gt;
&lt;P&gt;(Hmm… I hasten to send you that link (&lt;A href="http://www.sqlsaturday.com/"&gt;www.sqlsaturday.com&lt;/A&gt;), because frankly you will have to see that someone has a bad where clause on a query somewhere. I would offer up prizes for the best guess, but every time I do contests no one ever gets it or even tries.)&lt;/P&gt;
&lt;DIV class=wlWriterHeaderFooter style="PADDING-RIGHT:0px;PADDING-LEFT:0px;PADDING-BOTTOM:0px;MARGIN:0px;PADDING-TOP:0px;"&gt;





&lt;P&gt;&lt;A&gt;&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=13489" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Speaking/default.aspx">Speaking</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Commenting your code</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx</link><pubDate>Thu, 31 Jul 2008 02:19:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:8132</guid><dc:creator>drsql</dc:creator><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/8132.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=8132</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=8132</wfw:comment><description>&lt;p&gt;As I am easing back into real life from writing the book, I am in search of easy targets for blogging.&amp;#160; My boss mentioned &lt;a href="http://www.codinghorror.com/blog/archives/001150.html" target="_blank"&gt;this blog&lt;/a&gt; over on Jeff Atwood's Coding Horror Blog and it got me thinking about commenting.&amp;#160; His advice is to only comment &amp;quot;why&amp;quot; the code works.&amp;#160; I can't quite agree, because the code he claims to be acceptable is:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;private double SquareRootApproximation(n) {     &lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&amp;#160; r = n / 2;     &lt;br /&gt;&amp;#160; while ( abs( r - (n/r) ) &amp;gt; t ) {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; r = 0.5 * ( r + (n/r) );      &lt;br /&gt;&amp;#160; }      &lt;br /&gt;&amp;#160; return r;      &lt;br /&gt;}      &lt;br /&gt;System.out.println( &amp;quot;r = &amp;quot; + SquareRootApproximation(r) );&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I mean, it is better than some code I have seen,&amp;#160; but still, I would like a bit more information about why this works.&amp;#160; Maybe the name of the algorithm used, or at least what to do if this fails to provide the expected results.&amp;#160; Admittedly this is probably something that could be easily found, but most algorithms are not.&amp;#160; Comments in my mind should at least lead you to understand the mindset of the programmer.&amp;#160; What would actually improve this code in my mind is to change the variables to full words (though in this case it might not make sense to do this.) &lt;/p&gt;  &lt;p&gt;On an extremely different side of things is &lt;a href="http://www.mssqltips.com/tip.asp?tip=1213" target="_blank"&gt;this article&lt;/a&gt; from &amp;quot;&lt;a href="http://www.mssqltips.com/author.asp?authorid=11"&gt;Edgewood Solutions Engineers&lt;/a&gt;&amp;quot; on mssqltips.com. Their answer is to explain what the code is doing in simple terms, making sure to comment almost everything.&amp;#160; They have a very elaborate header devised, with dependencies, both users of the object and objects it used.&amp;#160; Most of what is said seems a bit like overkill, but their point here &amp;quot;Comment all of the major code blocks of the code and the critical minor points that can be easily overlooked such as a obscure WHERE clause.&amp;quot; is a good one.&amp;#160; I generally pepper my code with comments where I think it will be hard to debug for myself later, with a consideration for others, particularly when those others will call me to explain the code.&lt;/p&gt;  &lt;p&gt;Which brings me to my commenting philosophy. I personally think you have to comment to the expected lowest common denominator.&amp;#160; Think of the dumbest person who could have the need to read your code who is also qualified to have their job (otherwise you would have to write instructions on every line of code). If the qualified person can figure out what you are doing just by your naming conventions and , then it doesn't need comments. But if that person would look at the code and reasonable figure it out, then there is no need to comment the code.&amp;#160; What this requires is a few things:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Naming objects&lt;/strong&gt; - if your procedures, tables, columns, functions all have meaningful names, you won't have to explain what they mean, saving time&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Good design&lt;/strong&gt; - if the relationship between objects and the cardinality of those relationships is clear, then you don't need to explain that what you are doing is hack due to poor thinking...&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Naming variables&lt;/strong&gt; - probably the most important thing to avoid the need for comments is naming stuff.&amp;#160; Name variables with words, not single character values (except sometimes i, x, etc will suffice for obvious typical uses)&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Reasonable code formatting&lt;/strong&gt; - SQL has no real form, so you &lt;em&gt;could&lt;/em&gt; write procedures on a single line.&amp;#160; You could.&amp;#160; You could smash your hand with a hammer too.&amp;#160; Neither action would be very good.&amp;#160; (Consider using Red-Gate's SQL Refactor tool if nothing else.)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;However, the fact is, for SQL code, the real problem comes in when you start coming up with cool relational methods of solving problems that most moderately qualified people wouldn't get. For example the trick of using a sequence table to break apart a comma delimited list. Couple that with a join and you get some amazingly cool code, but how do you comment it?&lt;/p&gt;  &lt;p&gt;For example, say an architect that shouldn't be an architect designs a table with a comma delimited list like this (didn't I mention good design earlier?&amp;#160; I hate having to say this is a hack, but it is an elegant hack...)&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#008000"&gt;--excerpted from Chapter 7 of &lt;/font&gt;&lt;/em&gt;&lt;a href="http://www.apress.com/book/view/143020866x" target="_blank"&gt;&lt;em&gt;&lt;font color="#008000"&gt;Pro SQL Server 2008 Relational Database Design and Implementation&lt;/font&gt;&lt;/em&gt;&lt;/a&gt;    &lt;br /&gt;&lt;font face="Courier New" size="2"&gt;CREATE TABLE poorDesign      &lt;br /&gt;(      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; poorDesignId int,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; badValue varchar(20)      &lt;br /&gt;)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;INSERT INTO poorDesign --using 2008 syntax     &lt;br /&gt;VALUES (1,'1,3,56,7,3,6'),      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (2,'22,3'),      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; (3,'1')&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;&lt;/font&gt;You can &amp;quot;normalize&amp;quot; this set using a table of numbers (in my examples named tools.sequence) and a really cool join:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;SELECT&amp;#160;&amp;#160;&amp;#160; poorDesign.poorDesignId as betterDesignId,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SUBSTRING(',' + poorDesign.badValue + ',',i + 1,      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CHARINDEX(',',',' + poorDesign.badValue + ',',i + 1) - i - 1)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font face="Courier New" size="2"&gt;as betterScalarValue     &lt;br /&gt;FROM&amp;#160;&amp;#160;&amp;#160;&amp;#160; poorDesign      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; JOIN tools.sequence      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; on i &amp;gt;= 1      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AND i &amp;lt; LEN(',' + poorDesign.badValue + ',') - 1      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AND SUBSTRING(',' + + poorDesign.badValue + ',', i, 1) = ','&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;But are there enough pixels available on the planet to make that more understandable to most SQL programmers? Even the reasonably qualified?&amp;#160;&amp;#160; I mean, I am still kind of amazed at the technique and the fact that it returns the following:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;betterDesignId betterScalarValue     &lt;br /&gt;-------------- -----------------      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 56      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 7      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 6      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 22      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;still impresses me.&amp;#160; Frankly I don't know how to comment that code to make it readable.&amp;#160; In a real situation I would settle for a comment before the SELECT that stated:&lt;/p&gt;  &lt;p&gt;--Uses a table of numbers to parse the comma delimited list into a SQL acceptable format.   &lt;br /&gt;--If you don't understand this code, read this article: &lt;a title="http://www.sommarskog.se/arrays-in-sql-2005.html#tblnum" href="http://www.sommarskog.se/arrays-in-sql-2005.html#tblnum"&gt;http://www.sommarskog.se/arrays-in-sql-2005.html#tblnum&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Opinions? What do you use for a comments in your code?&amp;#160; Do you have commenting policies?&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8132" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Best+Practices/default.aspx">Best Practices</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Database+Design/default.aspx">Database Design</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Techniques/default.aspx">SQL Techniques</category></item><item><title>2008: Error List in 2008</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx</link><pubDate>Thu, 06 Mar 2008 03:40:47 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5474</guid><dc:creator>drsql</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/5474.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=5474</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=5474</wfw:comment><description>&lt;p&gt;Ok, so I was looking around for a blurb about plan guides for my anti ad hoc SQL section of my book (ok, maybe not completely anti- but that isn't the point,) when I found this blog: &lt;a title="http://geekswithblogs.net/Sreeblog/articles/117576.aspx" href="http://geekswithblogs.net/Sreeblog/articles/117576.aspx"&gt;http://geekswithblogs.net/Sreeblog/articles/117576.aspx&lt;/a&gt; that basically just lists some new features in 2008.&amp;nbsp; One that I hadn't seen I feel the need to mention.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Transact-SQL Error List Window: &lt;br&gt;SQL Server Management Studio includes an Error List window that displays the syntax and semantic errors generated from the IntelliSense code in the Transact-SQL Query Editor.  &lt;p&gt;If you haven't seen this, it is really kind of neat.&amp;nbsp; Say you type:  &lt;p&gt;select *&lt;br&gt;from sys.object&lt;br&gt;whe re name = 'fred'  &lt;p&gt;You can see the obvious errors, since this is a very small batch, but IntelliSense underlines sys.object and re in the batch.&amp;nbsp; Go to the View menu and show the Error List, and you will see something like this:  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/louis_davidson/WindowsLiveWriter/2008ErrorListin2008_130DA/image_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="321" alt="image" src="http://sqlblog.com/blogs/louis_davidson/WindowsLiveWriter/2008ErrorListin2008_130DA/image_thumb.png" width="582" border="0"&gt;&lt;/a&gt;&amp;nbsp; &lt;p&gt;Double-click on the error, it takes you to the error in the query window.&amp;nbsp; Obviously I have just discovered this, so please comment if you know more about this topic (particularly if it has been helpful to you or not) please chime in.&amp;nbsp; And thanks to Sreenivas Mogullapalli for the cool post, it had a few other things I didn't remember too (just don't make me have to pronounce your name...I am pretty sure I wouldn't get it right.)  &lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5474" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Tools/default.aspx">SQL Tools</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SSMS/default.aspx">SSMS</category></item><item><title>2008: Declaring and instantiating a value</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx</link><pubDate>Sun, 02 Mar 2008 00:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5390</guid><dc:creator>drsql</dc:creator><slash:comments>16</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/5390.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=5390</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=5390</wfw:comment><description>&lt;P&gt;Ok, I admit it.&amp;nbsp; Sometimes the least important things are the most fun.&amp;nbsp; As I try to get my blog back up and kicking again after a few months of holiday fun coupled with some dreary personal life things (a death in the family and lots of sickness/busyness, mostly,) I felt the need to write about another little time saving feature that you might not have heard of. Ever if you have it is still cool.&lt;/P&gt;
&lt;P&gt;This topic is declaring and instantiating a value in a single statement.&amp;nbsp; So what used to be:&lt;/P&gt;
&lt;P&gt;DECLARE @i int&lt;BR&gt;SET @i = 1&lt;/P&gt;
&lt;P&gt;Can now be:&lt;/P&gt;
&lt;P&gt;DECLARE @i int = 1&lt;/P&gt;
&lt;P&gt;Ho hum, I had thought earlier when I first saw this.&amp;nbsp; You know, it saves me 3 keystrokes. But today, I was doing some writing in my book and I realized that it isn't just limited to literals (it had just never crossed my mind) so when I was creating my savepoint names for nested savepoints.&amp;nbsp; You can use literals and functions, whatever you need.&lt;/P&gt;
&lt;P&gt;DECLARE @savepoint nvarchar(128) = cast(object_name(@@procid) AS nvarchar(125)) + cast(@@nestlevel AS nvarchar(3)) 
&lt;P&gt;All in one line of code...clean, neat.&amp;nbsp; And when I was writing a trigger that I could do this: 
&lt;P&gt;DECLARE @rowsAffected int = @@rowcount, --stores the number of rows affected&lt;BR&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; @msg varchar(2000) = '' --used to hold the error message 
&lt;P&gt;And save a couple of lines of code, and now, how much cleaner and effective is this code?&amp;nbsp; Not only does it save two lines of code to do the SET (or you could use SELECT), but it saves lines of whitespace too.&amp;nbsp; 
&lt;P&gt;Will this save a lot of time?&amp;nbsp; Probably not, but it is one of those long desired features that we SQL Server programmers are so glad to be getting.&amp;nbsp; In my case it is going to cost me time because I have to go back and re-edit places where I forgot about this syntax and didn't use it in my new book, which is one of the worst parts of writing.&amp;nbsp; When you mess up and forget something that is new and more or less essential, you can have to edit large amounts of code/text. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;The comment from Steve got me thinking if you could use&amp;nbsp;a query to instatiate the value.&amp;nbsp;&amp;nbsp; Survey says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;create table fred&lt;BR&gt;(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; value&amp;nbsp;&amp;nbsp; char(1)&lt;BR&gt;)&lt;BR&gt;go&lt;BR&gt;insert into fred&lt;BR&gt;values ('a'),('b'),('c')&lt;BR&gt;go&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;declare @value char(1) = (select MAX(value) from fred)&lt;/P&gt;
&lt;P&gt;select @value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;YES! This returns 'c', just as you would expect.&amp;nbsp; Okay, so now this is even cooler.&amp;nbsp; It doesn't work with table types though. And since we are feature complete, I assume it probably won't (I didn't expect it too, but it never hurts to try.)&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5390" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>2008: Rebuilding a Heap</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx</link><pubDate>Wed, 27 Feb 2008 04:10:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5295</guid><dc:creator>drsql</dc:creator><slash:comments>7</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/5295.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=5295</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=5295</wfw:comment><description>&lt;p&gt;In 2005, rebuilding a table that was a heap (no clustered index) wasn't easy.&amp;nbsp; You could copy it to a different table, or you could add a clustered index and then drop it. &lt;/p&gt; &lt;p&gt;In 2008, this is a far easier thing to do.&amp;nbsp; They have added to the ALTER TABLE command a method to rebuild the table, which is the same as rebuilding the clustered index for a clustered table, but for a HEAP, it is the only way to go.&amp;nbsp; &lt;/p&gt; &lt;p&gt;In the following code sample, I create a heap, load it will "little data", then expand every row to much larger values.&amp;nbsp; The result is a little bit of fragmentation, but more than that, tons of forwarding pointers (when a row won't fit on the same heap page, it gets moved to a different page, but the pointer to the row does not change in the indexes.)&amp;nbsp; Rebuilding the heap is now really simple:&lt;/p&gt; &lt;p&gt;&lt;font color="#004080"&gt;create table heapDemo&lt;br&gt;(&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; value varchar(1000)&lt;br&gt;)&lt;br&gt;GO&lt;br&gt;set nocount on&lt;br&gt;insert into heapDemo&lt;br&gt;select 'hi'&lt;br&gt;go 10000&lt;br&gt;--Expand the values to 500 times the size they were&lt;br&gt;update heapDemo&lt;br&gt;set value = replicate('hi',500)&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Now, check the stats of the table (using the index stats dmv, no less)&lt;/p&gt; &lt;p&gt;&lt;font color="#004080"&gt;select index_type_desc, fragment_count, page_count, forwarded_record_count&amp;nbsp; &lt;br&gt;from sys.dm_db_index_physical_stats(db_id(),default,default,default,'DETAILED')&lt;br&gt;where object_id = object_id('heapDemo')&lt;/font&gt; &lt;/p&gt; &lt;p&gt;This returns:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="1"&gt;index_type_desc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fragment_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; forwarded_record_count&lt;br&gt;--------------------- -------------------- -------------------- ----------------------&lt;br&gt;HEAP&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;&amp;nbsp;&amp;nbsp; 6&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1443&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;&amp;nbsp; 9961&lt;/font&gt;&lt;br&gt;&lt;/p&gt; &lt;p&gt;Now, you can rebuild the heap with the command:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font color="#004080"&gt;alter table heapDemo rebuild&lt;/font&gt;&lt;/strong&gt;&lt;br&gt;&lt;/p&gt; &lt;p&gt;Check the values now:&lt;/p&gt; &lt;p&gt;&lt;font color="#004080"&gt;select index_type_desc, fragment_count, page_count, forwarded_record_count&lt;br&gt;from sys.dm_db_index_physical_stats(db_id(),default,default,default,'DETAILED')&lt;br&gt;where object_id = object_id('heapDemo')&lt;/font&gt; &lt;/p&gt; &lt;p&gt;This shows no that the forwarded_record_count is 0, which is the idea situation for your heap.&lt;/p&gt;&lt;font face="Courier New" size="1"&gt;index_type_desc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fragment_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; forwarded_record_count&lt;br&gt;--------------------- -------------------- -------------------- ----------------------&lt;br&gt;HEAP&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;&amp;nbsp;&amp;nbsp; 3&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1440&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;&amp;nbsp; 0&lt;/font&gt;&lt;br&gt; &lt;p&gt;Nice new addition!&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5295" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Dynamic+Management+Objects/default.aspx">Dynamic Management Objects</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>Changing the owner of a database</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx</link><pubDate>Wed, 05 Dec 2007 05:06:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3690</guid><dc:creator>drsql</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/3690.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=3690</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=3690</wfw:comment><description>&lt;p&gt;Tonight, as I was creating my sample database for my chapter on implementing the database, I learned something new, that existed in 2005.&amp;nbsp; I had always used sp_changedbowner to change the owner of a database, but I was reading in another section about ALTER AUTHORIZATION earlier to change the owner of an object in a schema, so I said to my self "Louis" (I call myself that) "Louis, wonder if ALTER AUTHORIZATION works on other stuff?"&lt;/p&gt; &lt;p&gt;Bizarre and surreal conversations with myself aside, the answer was Yes, you sure could.&amp;nbsp; The syntax is:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;ALTER AUTHORIZATION ON Database::&amp;lt;databaseName&amp;gt; TO &amp;lt;serverPrincipal&amp;gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;To demonstrate, first, I will create a login:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;create login test with password = 'like, password, dude'&lt;br&gt;go&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Then a database just taking all of the defaults.&amp;nbsp; Setting an owner is not a part of the CREATE DATABASE syntax anyhow:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;create database showChangeOwner&lt;br&gt;go&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Then, check the owner:&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New"&gt;select SUSER_SNAME(owner_sid)&lt;br&gt;from&amp;nbsp;&amp;nbsp; sys.databases&lt;br&gt;where&amp;nbsp; name = 'showChangeOwner'&lt;/font&gt; &lt;/p&gt; &lt;p&gt;This will return the login that you resolve to when you created the database.&amp;nbsp; &lt;p&gt;&lt;font face="Courier New"&gt;MYDOMAIN\LBDAVI&lt;/font&gt;  &lt;p&gt;Next, run the following statement to change the owner: &lt;p&gt;&lt;strong&gt;ALTER AUTHORIZATION ON Database::showChangeOwner TO test&lt;/strong&gt;  &lt;p&gt;Then run the previous statement to see that the database is now owned by login: Test . &lt;p&gt;As an aside, if you use EXECUTE AS to change context to a different login, any database you create will be created as the user you are EXECUTING AS, so this could technically be the way to set the owner at creation time.&amp;nbsp; I will give the test login rights to create a database then execute as it. (My new favorite permission is "create any database".&amp;nbsp; I looked, but despite the connotation, there is not a "create almost any database", "create just this one database", or even "create database named fred" rights.  &lt;p&gt;&lt;font face="Courier New"&gt;grant create any database to test&lt;br&gt;execute as login = 'test'&lt;br&gt;create database showChangeOwner2 &lt;/font&gt; &lt;p&gt;Checking the owner again:  &lt;p&gt;select SUSER_SNAME(owner_sid)&lt;br&gt;from&amp;nbsp;&amp;nbsp; sys.databases&lt;br&gt;where&amp;nbsp; name = 'showChangeOwner2'  &lt;p&gt;Will show that this is owned by user "test". ALTER AUTHORIZATION will actually let you change the owner of quite a few different things.&amp;nbsp; For more information, please visit your public library...wait, no this is 2007, not 1970...&amp;nbsp; Check &lt;a href="http://msdn2.microsoft.com/en-us/library/ms187359.aspx" target="_blank"&gt;here&lt;/a&gt; in books online.&lt;/p&gt; &lt;p&gt;Don't forget to clean up!&lt;/p&gt; &lt;p&gt;drop database showChangeOwner, showChangeOwner2&lt;/p&gt; &lt;p&gt;&lt;em&gt;(did you know you could do that?&amp;nbsp; Saved me having to type drop database two times.&amp;nbsp; Wow, the time I saved by not typing drop database.&amp;nbsp; Wait, I typed drop database even more times after that.&amp;nbsp; And yes, this obvious lack of material is why I haven't been blogging of late...)&lt;/em&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3690" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>PASS Followup, Technical Edition</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx</link><pubDate>Tue, 25 Sep 2007 05:03:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2668</guid><dc:creator>drsql</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/2668.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=2668</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=2668</wfw:comment><description>&lt;P&gt;I have already given a rundown of most everything PASS &lt;A href="http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1807.entry" target=_blank&gt;here&lt;/A&gt;&amp;nbsp;on my personal blog, including a series of posts with pictures too over the &lt;A href="http://drsql.spaces.live.com/" target=_blank&gt;days of PASS&lt;/A&gt;) but since this blog is all about things technical with SQL Server, I wanted to just rundown of some of the cool stuff I learned about SQL Server 2008 that I hadn't heard before...&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;You can index a sql_variant&lt;/STRONG&gt; (script in &lt;A href="http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1793.entry" target=_blank&gt;this post&lt;/A&gt;)- possibly the least important piece of information is the most interesting.&amp;nbsp; A person asked Dejan Sarka in his session if you could index them, and no one really expected that you could.&amp;nbsp; Turns out, you can.... &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;Spatial Datatypes are going to rock!&lt;/STRONG&gt; - Really cool stuff.&amp;nbsp; (good high level&amp;nbsp;rundown &lt;A href="http://virtualearth.spaces.live.com/blog/cns!2BBC66E99FDCDB98!8675.entry" target=_blank&gt;here&lt;/A&gt;&amp;nbsp;on the Virtual Earth team blog).&amp;nbsp; They will support a flat earth model (like you use on a road map) and a round earth (well, ellipsoidal really) model as well, for more precise modeling of large spaces. Initially I thought this was going to be a fringe datatype and while it still might be one day in the future, I saw a lot of ideas I could use this for, even in an OLTP database.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;For example, if you have the longitude and latitude of&amp;nbsp;the address of a customer/constituent, it is going to be easy to join that point to the shape that represents a time zone, a country, the zip code, a voting district, etc, etc.&amp;nbsp; Or you could also do it at a zip code level, and join the shape of a zip code to the the other shapes it intersects with.&amp;nbsp; Of course, just like XML, these values will not always be exactly relational in nature (though you can make a case these types of datatypes represent a scalar value (a shape) while internally they might be made up of tons of points. &lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;Intellisense is a coming&lt;/STRONG&gt; - Yes, without an add-in, SQL Server 2008 tools will have intellisense.&amp;nbsp; Can't wait to see just how this works out for them.&amp;nbsp; Red Gate's version is ok, but it can be kind of clumsy to work with. Might even still be useful to have both...who knows.&amp;nbsp; The folks at Red-Gate are smart cookies.&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;Analysis Services 2008 will be evolutionary, not revolutionary&lt;/STRONG&gt; - This is a good thing really.&amp;nbsp; The change from 2000 to 2005 was big, huge, major.&amp;nbsp; The problem was, it was so huge that it was hard to figure out all of the bits and pieces.&amp;nbsp; Part of this was the tools were version one, and 2008 will take the tools to the next level.&amp;nbsp; The biggest neat stuff in there surrounded having the engine able to give warnings about how your cubes are designed.&amp;nbsp; Blue squiggly lines (Donald Farmer claimed this to be a new technical term: "squiggly" in his session on AS 2008) will show you warnings right in the UI, and red ones show errors.&amp;nbsp; Warnings can be ignored, errors not so much.&amp;nbsp; Apparently you can use the new tools to modify 2005 cubes too, though you won't be able to use any new functionality that does get added to 2008.&lt;BR&gt;
&lt;LI&gt;&lt;STRONG&gt;T-SQL is making small amounts of progress forward&lt;/STRONG&gt; - As a person who basically makes his living on relational database design, and T-SQL, I am a bit disappointed by how little T-SQL is changing.&amp;nbsp; I am particularly desirous of lots of usability tweaks being done to T-SQL (like why do something about &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124490" target=_blank&gt;delayed name resolution on procedures&lt;/A&gt; or &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=127219" target=_blank&gt;especially CREATE OR ALTER syntax for creating objects&lt;/A&gt;).&amp;nbsp; To me, the biggest wins for DBA could be done at what should be the least cost to the dev team.&amp;nbsp; Both of the ideas stated would only matter to the compiler, right? So nothing in the engine that executes queries need to change.&amp;nbsp; Just the compiler, and with delayed name resolution, we already have both situations implemented (functions do not allow delayed name resolution) so it should be mostly cosmetic.&lt;BR&gt;&lt;BR&gt;This however is only my perception, and if they came back and said on the connect site that it was too hard because, well, I would never disagree with them, since all I can program in is T-SQL.&amp;nbsp; And it isn't that they are completely ignoring T-SQl, there are a few interesting enhancements, such as the one's Jamie points out &lt;A href="http://blogs.conchango.com/jamiethomson/archive/2007/06/04/Katmai_3A00_-New-T_2D00_SQL-enhancements.aspx" target=_blank&gt;here&lt;/A&gt;&amp;nbsp;involving variable initialization, &amp;nbsp;and row constructors to allow &amp;gt; 1 row in an insert statement. Check &lt;A href="http://coolthingoftheday.blogspot.com/2007/08/more-sql-server-2008-t-sql-coolness.html" target=_blank&gt;this post&lt;/A&gt; by Greg Duncan for a bit more coolness on that subject.&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Change data capture&lt;/STRONG&gt; - This is going to be a very interesting addition to the platform.&amp;nbsp; It will allow you to get information about what rows have been changed in your database (each and every time the row changes), much like we have done with triggers for years (they claim a great performance improvement over triggers (sounds like the race is on!)).&amp;nbsp; This will allow very finely grained ETL in a nice package.&amp;nbsp; (See post &lt;A class="" href="http://blog.benhall.me.uk/2007/06/sql-server-2008-change-data-capture-cdc.html" target=_blank&gt;here&lt;/A&gt; for better overview) The downside of course, is that CDC is only going to be available in Enterprise Edition.&amp;nbsp; For all other versions, there will be a feature called Change Tracking that will keep up with what keys of rows that have been modified (even deleted).&amp;nbsp; This will give users of other editions a pretty good tool for seeing rows that have changed.&lt;BR&gt;&lt;BR&gt;I am probably the most excited about this feature, since it will allow ETL to be created in a natural way without building triggers or relying on date and time stamp values that you need to maintain.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is certainly not an exhaustive list (I expect that if you are reading this blog, you have seen the new date types, if not try &lt;A class="" href="http://blogs.msdn.com/manisblog/archive/2007/08/28/sql-server-2008-enhancements-in-date-and-time-data-types.aspx" target=_blank&gt;this post&lt;/A&gt;.&amp;nbsp; I saw a pretty exhaustive list in a private session.&amp;nbsp; Lots of really cool fun stuff is coming in the upcoming CTP's leading up to release sometime in 2008 (no scoop there, huh?)&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp;Edit: Forgot about change data capture&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2668" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/PASS/default.aspx">PASS</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>sys.dm_db_index_operational_stats</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/sys-dm-db-index-operational-stats.aspx</link><pubDate>Sun, 26 Aug 2007 20:12:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2341</guid><dc:creator>drsql</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/2341.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=2341</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=2341</wfw:comment><description>&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;
&lt;P&gt;This object provides very useful stats on how many times an index has been used, locked, waited on, etc. An index in this context can mean several things: a clustered index, heap, index, or a partition of either of these. The grain of the function is down to the partition level, so if you are working with a table that is partitioned into five parts, it will return 5 rows (In the previous section, &lt;B&gt;sys.dm_db_index_usage_stats&lt;/B&gt; would have seen the object as only a single row) 
&lt;P&gt;This object will give you a deep feel for how indexes are being used, and just exactly how much the index is costing you. It does this in part by telling you how often the index is modified at the Leaf level or non-leaf level, as well as how often users waited on blocks associated with the object, which can mean SQL Server locks, or even hardware or I/O latches. 
&lt;P&gt;&lt;B&gt;Type&lt;/B&gt;: function 
&lt;P&gt;&lt;B&gt;Parameters:&lt;/B&gt; &lt;B&gt;database_id , object_id, index_id, partition_number&lt;/B&gt; (each parameter can be &lt;B&gt;NULL&lt;/B&gt; or &lt;B&gt;DEFAULT&lt;/B&gt; if you want to return all rows) 
&lt;P&gt;&lt;B&gt;Data:&lt;/B&gt; accumulating refreshed when server is restarted or (perhaps obviously) when the index is dropped and recreated. Statistics live on when the index is rebuild, reorganized, and even when it is disabled and rebuilt. 
&lt;P&gt;&lt;B&gt;Columns:&lt;/B&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;database_id&lt;/B&gt;, &lt;B&gt;object_id, index_id &lt;/B&gt;-identifies the index in question&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;partition_number &lt;/B&gt;- 1 for non-partitioned tables. For partitioned tables will be the 1 – based number of the partition.&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_insert_count – &lt;/B&gt;the number of times a new row was added to the leaf of the index&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_delete_count – &lt;/B&gt;the number of times a row was deleted from the leaf&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_update_count – &lt;/B&gt;the number of changes to index keys for this index&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_ghost_count – &lt;/B&gt;the number of ghost records that have been marked as deleted but not cleaned up by SQL Server (&lt;A title=http://www.sql-server-performance.com/tips/glossary_p1.aspx href="http://www.sql-server-performance.com/tips/glossary_p1.aspx"&gt;http://www.sql-server-performance.com/tips/glossary_p1.aspx&lt;/A&gt;)&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;nonleaf_insert_count, nonleaf_delete_count, nonleaf_update_count – &lt;/B&gt;Same as the leaf page values, except for the b-tree index pages&lt;B&gt; &lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_allocation_count, nonleaf_allocation_count – &lt;/B&gt;The number of page allocated to the leaf and non-leaf pages of the index, respectively.&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;leaf_page_merge_count, nonleaf_page_merge_count – &lt;/B&gt;The&lt;B&gt; &lt;/B&gt;number of pages in the index that have been merged into a single page.&lt;B&gt; &lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;range_scan_count - &lt;/B&gt;number of times the index has been used in a range scan operator&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;singleton_lookup_count – &lt;/B&gt;number of times the index has been used to fetch a single row&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;forwarded_fetch_count – &lt;/B&gt;for a heap, shows the number of forward pointers have been used to resolve a query (&lt;A href="http://sqlblog.com/blogs/hugo_kornelis/archive/2006/11/03/The-table-scan-from-hell.aspx"&gt;http://sqlblog.com/blogs/hugo_kornelis/archive/2006/11/03/The-table-scan-from-hell.aspx&lt;/A&gt;)&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;lob_fetch_in_pages, lob_fetch_in_bytes – &lt;/B&gt;Quantifies the number of large object (varchar(max), varbinary(max), text, etc) have been retrieved using this index&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;lob_orphan_create_count, lob_orphan_insert_count – &lt;/B&gt;total number of large object pages orphaned by bulk operations &lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;row_overflow_fetch_in_pages , row_overflow_fetch_in_bytes – &lt;/B&gt;Quantifies the amount of data retrieved from row overflow pages for rows greater than one page in size&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;column_value_push_off_row_count, column_value_pull_in_row_count – &lt;/B&gt;Number of pages of large object or row overflow pages that have been moved by an in-row data operation&lt;B&gt; &lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;row_lock_count – &lt;/B&gt;number of row locks that have been requested against this&lt;B&gt; &lt;/B&gt;index&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;row_lock_wait_count &lt;/B&gt;– number of times a process has waited on a row lock against this index&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;row_lock_wait_in_ms &lt;/B&gt;– amount of time spent waiting on a row lock against this index&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;page_lock_count, page_lock_wait_count, page_lock_wait_in_ms &lt;/B&gt;– same as row_lock values at the page grain&lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;index_lock_promotion_attempt_count, index_lock_promotion_count – &lt;/B&gt;number of times the lock grain for an operation using this index was attempted or granted to be escalated (like from row to page)&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;page_latch_wait_count , page_latch_wait_in_ms – &lt;/B&gt;number&lt;B&gt; &lt;/B&gt;of waits and time waited on the physical page of the object to have the latch removed &lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;page_io_latch_wait_count, page_io_latch_wait_in_ms - &lt;/B&gt;number&lt;B&gt; &lt;/B&gt;of waits and time waiting on and I/O operation on a physical page of the object to be completed &lt;B&gt;&lt;/B&gt;&lt;/LI&gt;
&lt;LI&gt;This object is related to the &lt;B&gt;sys.dm_db_index_usage_stats&lt;/B&gt; in that they both provide information about how the index is used. This object, however, gives more detailed information about the inner workings of how the index is used at a physical level, whereas the usage stats is more of a feel for how it is used by the optimizer to satisfy the needs of certain queries. Use usage stats if you want counts of each usage, as each usage counts as 1. The operational stats object may have multiple values set for each type of activity recorded. (&lt;A href="http://blogs.msdn.com/sqlcat/archive/2005/12/12/502735.aspx"&gt;http://blogs.msdn.com/sqlcat/archive/2005/12/12/502735.aspx&lt;/A&gt;)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Examples:&lt;/B&gt; 
&lt;P&gt;Tables where the most latch contention is occurring 
&lt;P&gt;select object_schema_name(ddios.object_id) + '.' + object_name(ddios.object_id) as objectName,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; indexes.name, case when is_unique = 1 then 'UNIQUE ' else '' end + indexes.type_desc&amp;nbsp;as index_type,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; page_latch_wait_count , page_io_latch_wait_count&lt;BR&gt;from&amp;nbsp; &lt;B&gt;sys.dm_db_index_operational_stats(db_id(),null,null,null)&lt;/B&gt; as ddios&lt;BR&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; join sys.indexes&lt;BR&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on indexes.object_id = ddios.object_id&lt;BR&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;&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; and indexes.index_id = ddios.index_id&lt;BR&gt;order by page_latch_wait_count + page_io_latch_wait_count desc&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;Note:&amp;nbsp; This is part of an ongoing project to write a book about all of the dynamic management views for &lt;/FONT&gt;&lt;A href="http://www.red-gate.com/" target=_blank&gt;&lt;FONT face="Courier New" color=#02469b&gt;Red-Gate&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;.&amp;nbsp;It will be freely distributable once complete as an ebook.&amp;nbsp;Any examples, suggestions, corrections are desired and will certainly be mentioned in the final book.&amp;nbsp; Also, I will begin maintaining the following web page once the book is closer to completion: &lt;/FONT&gt;&lt;A href="http://drsql.org/dmvbook.aspx"&gt;&lt;FONT face="Courier New" color=#02469b&gt;http://drsql.org/dmvbook.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Courier New"&gt;. &lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2341" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Dynamic+Management+Objects/default.aspx">Dynamic Management Objects</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>sys.dm_exec_query_optimizer_info</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2007/08/06/sys-dm-exec-query-optimizer-info.aspx</link><pubDate>Tue, 07 Aug 2007 00:40:55 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2141</guid><dc:creator>drsql</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/louis_davidson/comments/2141.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/louis_davidson/commentrss.aspx?PostID=2141</wfw:commentRss><wfw:comment>http://sqlblog.com/blogs/louis_davidson/rsscomments.aspx?PostID=2141</wfw:comment><description>&lt;p&gt;Information about how queries have been optimized since the server has been restarted. Note that counters are only affected when there is some sort of optimization event, not on every query. (reference: &lt;a href="http://sqlserver-qa.net/blogs/perftune/archive/2007/05/11/get-statistics-on-query-plan-optimizer-execution.aspx"&gt;http://sqlserver-qa.net/blogs/perftune/archive/2007/05/11/get-statistics-on-query-plan-optimizer-execution.aspx&lt;/a&gt; )&lt;/p&gt; &lt;p&gt;&lt;b&gt;Type&lt;/b&gt;: View &lt;p&gt;&lt;b&gt;Data&lt;/b&gt;: Accumulating reset at restart &lt;p&gt;&lt;b&gt;Columns:&lt;/b&gt; &lt;ul&gt; &lt;li&gt;&lt;b&gt;counter&lt;/b&gt; - Name of the query&lt;/li&gt; &lt;li&gt;&lt;b&gt;occurrence – &lt;/b&gt;Number of times&lt;b&gt; &lt;/b&gt;the counter was recorded to&lt;b&gt;&lt;/b&gt;&lt;/li&gt; &lt;li&gt;&lt;b&gt;value – &lt;/b&gt;May or may not have some value, but is typically an average of the values that were recorded when the counter was written to (for a complete list of counters, check the books online documentation on sys.dm_exec_query_optimizer_info (1))&lt;b&gt;&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;b&gt;Example:&lt;/b&gt; &lt;p&gt;As an example, on a low use server, I restarted the server and executed: &lt;p&gt;select counter,occurrence, value&lt;br&gt;from sys.dm_exec_query_optimizer_info  &lt;p&gt;You will get values like: &lt;p&gt;&lt;font face="Courier New" size="2"&gt;counter&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; occurrence&amp;nbsp;&amp;nbsp;&amp;nbsp; value&lt;br&gt;----------------- ------------- -------------------- &lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;optimizations&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&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;1&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;elapsed time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0235776097702821&lt;br&gt;final cost&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.1957E-05&lt;/font&gt; &lt;p&gt;This tells you the number of statements that have been optimized and a plan created (the same value is for all three of the displayed counters), the average elapsed time spent compiling in the value column for the elapsed time row, and finally, the average final cost in the final cost row. Using these counters and some of the others you will discover will help you to determine how often statements ae being compiled. &lt;p&gt;Execute it again, it will give you the same values (assuming you are the only user, of course.) Now, execute the same query, this time making it uppercase, forcing another complication, since plans must match in every way: &lt;p&gt;SELECT COUNTER, OCCURRENCE, VALUE&lt;br&gt;FROM SYS.DM_EXEC_QUERY_OPTIMIZER_INFO  &lt;p&gt;You will see that the occurrences have increased, and there may be some difference in the average time it took: &lt;p&gt;&lt;font face="Courier New" size="2"&gt;counter&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; occurrence&amp;nbsp;&amp;nbsp;&amp;nbsp; value&lt;br&gt;----------------- ------------- -------------------- &lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;optimizations&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&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;1&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;elapsed time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.020978588737036&lt;br&gt;final cost&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.1957E-05&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;---------------------------------------&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;Note:&amp;nbsp; This is part of an ongoing project to write a book about all of the dynamic management views for &lt;a href="http://www.red-gate.com" target="_blank"&gt;Red-Gate&lt;/a&gt;.&amp;nbsp;It will be freely distributable once complete as an ebook.&amp;nbsp;Any examples, suggestions, corrections are desired and will certainly be mentioned in the final book.&amp;nbsp; Also, I will begin maintaining the following web page once the book is closer to completion: &lt;a href="http://drsql.org/dmvbook.aspx"&gt;http://drsql.org/dmvbook.aspx&lt;/a&gt;. &lt;/font&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2141" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/Dynamic+Management+Objects/default.aspx">Dynamic Management Objects</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx">T-SQL</category></item></channel></rss>