<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Louis Davidson</title><subtitle type="html" /><id>http://sqlblog.com/blogs/louis_davidson/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblog.com/blogs/louis_davidson/atom.aspx" /><generator uri="http://communityserver.org" version="2.1.61129.1">Community Server</generator><updated>2007-08-26T16:52:00Z</updated><entry><title>Apologies for comments going unpublished</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx</id><published>2008-07-31T02:49:51Z</published><updated>2008-07-31T02:49:51Z</updated><content type="html">&lt;p&gt;I had quite a few comments out there that were unpublished.&amp;#160; One person was particularly slighted and I am sending him a &amp;quot;sorry&amp;quot; gift.&amp;#160; I was stuck in &amp;quot;writer rut&amp;quot; and forgot about the fact that comments have to be allowed when people first come to the site (to eliminate spam!)&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Apologies for comments going unpublished&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Apologies for comments going unpublished%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx" target="_blank" title = "Email Apologies for comments going unpublished"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx&amp;amp;title=Apologies+for+comments+going+unpublished" target="_blank" title = "Submit Apologies for comments going unpublished to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx&amp;amp;phase=2" target="_blank" title = "Submit Apologies for comments going unpublished to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx&amp;amp;title=Apologies+for+comments+going+unpublished" target="_blank" title = "Submit Apologies for comments going unpublished to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx&amp;amp;title=Apologies+for+comments+going+unpublished" target="_blank" title = "Submit Apologies for comments going unpublished to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/apologies-for-comments-going-unpublished.aspx&amp;amp;title=Apologies+for+comments+going+unpublished&amp;amp;;top=1" target="_blank" title = "Add Apologies for comments going unpublished to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8136" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>Commenting your code</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx</id><published>2008-07-31T02:19:43Z</published><updated>2008-07-31T02:19:43Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Commenting your code&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Commenting your code%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx" target="_blank" title = "Email Commenting your code"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx&amp;amp;title=Commenting+your+code" target="_blank" title = "Submit Commenting your code to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx&amp;amp;phase=2" target="_blank" title = "Submit Commenting your code to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx&amp;amp;title=Commenting+your+code" target="_blank" title = "Submit Commenting your code to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx&amp;amp;title=Commenting+your+code" target="_blank" title = "Submit Commenting your code to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/30/commenting-your-code.aspx&amp;amp;title=Commenting+your+code&amp;amp;;top=1" target="_blank" title = "Add Commenting your code to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8132" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>Triggers...Evil?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx</id><published>2008-07-13T23:16:53Z</published><updated>2008-07-13T23:16:53Z</updated><content type="html">&lt;p&gt;Say it isn't so. &amp;quot;It isn't so.&amp;quot;&amp;#160; Glenn Berry thinks so in his post &lt;a href="http://glennberrysqlperformance.spaces.live.com/blog/cns!45041418ECCAA960!972.entry" target="_blank"&gt;here&lt;/a&gt;. When I read his post I thought I was going to really get into it with Conor's post &lt;a href="http://www.sqlskills.com/blogs/conor/2008/06/18/TheTroubleWithTriggers.aspx" target="_blank"&gt;here&lt;/a&gt;, called the Trouble with Triggers (a title which I had to post because I like Star Trek too,) but frankly I agree with Conor.&amp;#160; Triggers are great tools, when applied correctly.&amp;#160; When they are used in a bad way (which is quite often, from the code I have seen), well, agree with Glenn I must...&lt;/p&gt;  &lt;p&gt;In my book, I advocate triggers for a few things:&lt;/p&gt;  &lt;p&gt;* &lt;i&gt;Cross-database referential integrity (RI)&lt;/i&gt;: Just basic RI, but SQL Server doesn&amp;#8217;t manage declarative constraints across database boundaries. &lt;/p&gt;  &lt;p&gt;* &lt;i&gt;Intra-table, inter-row constraints&lt;/i&gt;: For example, when you need to see that the sum of a column value over multiple rows is less than some value (possibly in another table). &lt;/p&gt;  &lt;p&gt;* &lt;i&gt;Inter-table constraints&lt;/i&gt;: For example, if a value in one table relies on the value in another. This might also be written as a functions-based CHECK constraint, but it is often more maintainable to use a trigger. &lt;/p&gt;  &lt;p&gt;* &lt;i&gt;Introducing desired side effects to your queries&lt;/i&gt;: For example, cascading inserts, maintaining denormalized data, and so on.&lt;/p&gt;  &lt;p&gt;(and I give examples of each.) but I also am careful to say to be extremely careful with them. When my tech reviewer got to the start of my section on triggers, he quickly said that he didn't like them and they shouldn't be used.&amp;#160; By the end he agreed with my examples.&amp;#160; The problem with triggers is just like the problem with several tools that SQL Server gives you.&amp;#160; For example:&lt;/p&gt;  &lt;p&gt;* &lt;em&gt;Stored procedures:&lt;/em&gt; If used to encapsulate set based SQL calls into precompiled batches...good.&amp;#160; Used as a functional language to do work row by row, often with cursors...not so good.&amp;#160; Used to implement lots of business rules...well, that depends on the business rules but often this is where the real trouble comes (that is a future post)&lt;/p&gt;  &lt;p&gt;* &lt;em&gt;Cursors&lt;/em&gt;: Used to do some repetitive task, usually for some maintenance use...good.&amp;#160; Used in place of set based operations because the programmer cannot write good SQL...baaaddd (said properly should sound like a bleating sheep.)&lt;/p&gt;  &lt;p&gt;* &lt;em&gt;Clustered indexes&lt;/em&gt;: Used to cluster on the right sort of key (like a small monotonically increasing value)...good.&amp;#160; Used to cluster on a random value, like a guid...not so good.&amp;#160; Never used as a search argument of any kind, forcing bookmark lookups constantly....well, yuck.&lt;/p&gt;  &lt;p&gt;So just like you don't hammer in a nail with a wrench, or hammer in a screw with any implement, triggers are not to be used improperly.&amp;#160; The problem is that of education.&amp;#160; There are so many people out there who just do what it is they feel like without regards for what is actually correct.&amp;#160; SQL programmers try to do everything in SQL (I have been guilty of this many times) and functional programmers try to do everything one operation at a time.&amp;#160; Some day, once we all trust the SQLCLR to the extent we ought to, perhaps the exact balance can be achieved.&lt;/p&gt;  &lt;p&gt;And Glenn, I completely agree with your reasons to hate triggers: &amp;quot;I witnessed first hand the consequences of over-use of DML triggers in a large, n-tier client/server application.&amp;quot;&amp;#160; I think the important thing in there is the word &amp;quot;over-use.&amp;quot;&amp;#160; I mean, a person could probably get fat eating only celery and drinking water if they over did that.&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Triggers...Evil?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Triggers...Evil?%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx" target="_blank" title = "Email Triggers...Evil?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&amp;amp;title=Triggers...Evil%3f" target="_blank" title = "Submit Triggers...Evil? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&amp;amp;phase=2" target="_blank" title = "Submit Triggers...Evil? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&amp;amp;title=Triggers...Evil%3f" target="_blank" title = "Submit Triggers...Evil? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&amp;amp;title=Triggers...Evil%3f" target="_blank" title = "Submit Triggers...Evil? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&amp;amp;title=Triggers...Evil%3f&amp;amp;;top=1" target="_blank" title = "Add Triggers...Evil? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7805" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>See you at Tech Ed? Or other places?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx</id><published>2008-05-30T19:48:36Z</published><updated>2008-05-30T19:48:36Z</updated><content type="html">&lt;p&gt;Next week is Tech Ed Developers, and I will be there working at the OLTP demo station from:&lt;/p&gt;  &lt;p&gt;Tuesday 11:45 &amp;#8211; 2:45    &lt;br /&gt;Wednesday 2:30 &amp;#8211; 6:00     &lt;br /&gt;Thursday 11:45 &amp;#8211; 2:45     &lt;br /&gt;Friday 11:45 &amp;#8211; 2:45&lt;/p&gt;  &lt;p&gt;All times Eastern Daylight Saving Time and a little bit approximate at this point.&amp;#160; Please stop by and say howdy!&amp;#160; I don't exactly yet know what I will be doing completely, but it will be fun, never the less.&lt;/p&gt;  &lt;p&gt;After that I have a few other speaking engagements coming up:&lt;/p&gt;  &lt;p&gt;Nashville SQL User's Group - Late Summer - Doing some session in concert with my book release (hopefully doing some special stuff that time too.&amp;#160; Stay tuned for that announcement)   &lt;br /&gt;Devlink (&lt;a href="http://www.devlink.net"&gt;www.devlink.net&lt;/a&gt;) - August 22, 23 - Doing a double session on Database Design with Paul Nielsen    &lt;br /&gt;PASS (&lt;a href="http://www.sqlpass.org"&gt;www.sqlpass.org&lt;/a&gt;) - Nov 19-21 - Doing the same session with Paul, just condensed into a single session&lt;/p&gt;  &lt;p&gt;I will be back in the forums soon, and on this blog and my personal website (drsql.org) too as the principal writing for the book will be finished tomorrow, and rewrites in a week or so.&amp;#160; After that, it is a downhill journey to the finish line.&lt;/p&gt;  &lt;p&gt;So come by next week and let me know you are reading the blog, book, or whatever.&amp;#160; &lt;/p&gt;  &lt;p&gt;(cross-posted to drsql.spaces.live.com)&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=See you at Tech Ed? Or other places?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09See you at Tech Ed? Or other places?%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx" target="_blank" title = "Email See you at Tech Ed? Or other places?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx&amp;amp;title=See+you+at+Tech+Ed%3f+Or+other+places%3f" target="_blank" title = "Submit See you at Tech Ed? Or other places? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx&amp;amp;phase=2" target="_blank" title = "Submit See you at Tech Ed? Or other places? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx&amp;amp;title=See+you+at+Tech+Ed%3f+Or+other+places%3f" target="_blank" title = "Submit See you at Tech Ed? Or other places? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx&amp;amp;title=See+you+at+Tech+Ed%3f+Or+other+places%3f" target="_blank" title = "Submit See you at Tech Ed? Or other places? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/05/30/see-you-at-tech-ed-or-other-places.aspx&amp;amp;title=See+you+at+Tech+Ed%3f+Or+other+places%3f&amp;amp;;top=1" target="_blank" title = "Add See you at Tech Ed? Or other places? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7085" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>Sequence Table Tricks</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx</id><published>2008-03-23T14:06:50Z</published><updated>2008-03-23T14:06:50Z</updated><content type="html">&lt;p&gt;Ok, so I am writing about the kinds of things you can do with a sequence table, and I have built the table, I have the typical kinds of things planned (like splitting a string, and for the next section, loading a calendar table) but I wanted to do something interesting.&amp;#160; And frankly, sometimes the path to solving a real problem starts with with solving an abstract problem, then reality often tosses you a problem that is really close to this.&amp;#160; Admittedly this might not be realistic in my case, but it is possible.&lt;/p&gt;  &lt;p&gt;I have just recently watched the Futurama video &amp;quot;Bender's Big Score&amp;quot; and they have a little math lesson section on the video that was very interesting, but the thing that stuck in my mind was this reference back to a previous episode called the &amp;quot;&lt;a href="http://www.things.org/~jym/y3k/2ACV06.html" target="_blank"&gt;Lesser of Two Evils&lt;/a&gt;&amp;quot;.&amp;#160; The Bender look-alike named Flexo (they are both Bender units) start talking and have the following exchange:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Bender: &lt;/b&gt;Hey, brobot, what's your serial number?     &lt;br /&gt;&lt;b&gt;Flexo: &lt;/b&gt;3370318.     &lt;br /&gt;&lt;b&gt;Bender: &lt;/b&gt;No way! Mine's 2716057!     &lt;br /&gt;&lt;b&gt;Fry: &lt;/b&gt;I don't get it.     &lt;br /&gt;&lt;b&gt;Bender: &lt;/b&gt;We're both expressible as the sum of two cubes! &lt;/p&gt;  &lt;p&gt;So I figured, the sum of two cubes would be an interesting, and pretty easy abstract utilization of the sequence table.&amp;#160; Then I have found this reference also to &lt;a href="http://www.sciencenews.org/articles/20020727/mathtrek.asp" target="_blank"&gt;&amp;quot;taxicab&amp;quot; numbers,&lt;/a&gt; where the goal is to discover the smallest value that can be expressed as the sum of three cubes in N different ways.&lt;/p&gt;  &lt;p&gt;How hard is the query? Turns out, that once you have a sequence table with numbers from 1 to 100000 or so, you can calculate that Taxicab(2) = 1729 very easily (and all of the other numbers that are the sum of two cubes too), and the the sum of two cubes in three different ways also pretty easily (took 3 seconds on my laptop, and that value is 87539319).&amp;#160; &lt;/p&gt;  &lt;p&gt;Here is the code:&lt;/p&gt;  &lt;p&gt;declare @level int &lt;/p&gt;  &lt;p&gt;set @level = 2 --sum of two cubes &lt;/p&gt;  &lt;p&gt;;with cubes as    &lt;br /&gt;(select POWER(i,3) as i3     &lt;br /&gt;from&amp;#160;&amp;#160; tools.sequence     &lt;br /&gt;where&amp;#160; i &amp;gt;= 1 and i &amp;lt; 500) --&amp;lt;&amp;lt;&amp;lt;Vary for performance, and for cheating reasons, max needed value     &lt;br /&gt;    &lt;br /&gt;select c1.i3 + c2.i3 as [sum of 2 cubes in N Ways]     &lt;br /&gt;from&amp;#160;&amp;#160; cubes as c1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cross join cubes as c2     &lt;br /&gt;where c1.i3 &amp;lt;= c2.i3     &lt;br /&gt;group by (c1.i3 + c2.i3)     &lt;br /&gt;having count(*) = @level     &lt;br /&gt;order by 1 &lt;/p&gt;  &lt;p&gt;Ok, breaking this down the cubes CTE is pretty simple: &lt;/p&gt;  &lt;p&gt;(select power(i,3) as i3    &lt;br /&gt;from&amp;#160;&amp;#160; tools.sequence&amp;#160; --the table holds 100000 values     &lt;br /&gt;where&amp;#160; i &amp;gt;= 1 and i &amp;lt; 500) &lt;/p&gt;  &lt;p&gt;This transforms our values to a table of cubes, so the values would be 1, 8, 27, 64, etc.&amp;#160; The query is a bit more interesting. We want the lowest value that meets the criteria that present in a second, so top is used.&amp;#160; I sum the two cube values, which I get from cross joining the CTE twice. &lt;/p&gt;  &lt;p&gt;select c1.i3 + c2.i3 as [sum of 2 cubes in N Ways]    &lt;br /&gt;from&amp;#160;&amp;#160; cubes as c1     &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; cross join cubes as c2     &lt;br /&gt;where c1.i3 &amp;lt;= c2.i3 --this gets rid of the &amp;quot;duplicate&amp;quot; value pairs &lt;/p&gt;  &lt;p&gt;The where condition of c1.i3 &amp;lt;= c2.i3 gets rid of the &amp;quot;duplicate&amp;quot; value pairs since c1 and c2 have the same values, so without this, for 1729 you would get:&lt;/p&gt;  &lt;p&gt;c1.&lt;font face="Courier New" size="2"&gt;i3&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; c2.i3      &lt;br /&gt;-------------------- --------------------       &lt;br /&gt;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;&amp;#160;&amp;#160;&amp;#160; 1728       &lt;br /&gt;729&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; 1000&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;1000&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; 729      &lt;br /&gt;1728&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;These pairs are the same.&amp;#160; I don't eliminate equality to allow for the case where both number are equal, because they won't be doubled up.&amp;#160; With these values:&lt;/p&gt; c1.&lt;font face="Courier New" size="2"&gt;i3&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; c2.i3    &lt;br /&gt;-------------------- --------------------     &lt;br /&gt;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;&amp;#160;&amp;#160;&amp;#160; 1728     &lt;br /&gt;729&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; 1000&lt;/font&gt;   &lt;p&gt;You can see that 1729 is the sum of two cubes in two different ways.&amp;#160; So, lastly, the question of performance must come up.&amp;#160; Reading the articles, it is clear that this is not a terribly easy problem to solve.&amp;#160; Values for the sum of three cubes is fairly simple, leaving the sequence values bounded at 500, I get two values in around one second. &lt;/p&gt;  &lt;p&gt;[sum of 2 cubes in N Ways]    &lt;br /&gt;---------------------------------     &lt;br /&gt;87539319     &lt;br /&gt;119824488 &lt;/p&gt;  &lt;p&gt;Four however, was a &amp;quot;bit&amp;quot; more challenging.&amp;#160; Knowing the answer from the article, I knew I could bound my numbers using 20000 and get the answer.&amp;#160; Using this &amp;quot;cheat&amp;quot; on my laptop, I was able to calculate the value of taxicab(4) was 6963472309248 (yea, it only found one) in just 1 hour and 33 minutes, this on a 2.2 Ghz Pentium M laptop with 2 GB of RAM. I tried calculating taxicab(5), but alas, I ran out of space for tempdb (and I had 50 GB available.)&amp;#160; For that you had to go up to i being greater than something like 350000....&lt;/p&gt;  &lt;p&gt;I am thinking that if I turn the CTE into a physical, indexed table I would be able to do this.&amp;#160; And for 6, perhaps using the precision of the numeric datatype (38 places!), but not today, I don't want to melt my computer trying something this abstract.&amp;#160; Well at least not just yet, perhaps when the &lt;a href="http://www.apress.com/book/view/143020866x" target="_blank"&gt;book&lt;/a&gt; is done...&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Sequence Table Tricks&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Sequence Table Tricks%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx" target="_blank" title = "Email Sequence Table Tricks"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx&amp;amp;title=Sequence+Table+Tricks" target="_blank" title = "Submit Sequence Table Tricks to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx&amp;amp;phase=2" target="_blank" title = "Submit Sequence Table Tricks to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx&amp;amp;title=Sequence+Table+Tricks" target="_blank" title = "Submit Sequence Table Tricks to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx&amp;amp;title=Sequence+Table+Tricks" target="_blank" title = "Submit Sequence Table Tricks to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/23/sequence-table-tricks.aspx&amp;amp;title=Sequence+Table+Tricks&amp;amp;;top=1" target="_blank" title = "Add Sequence Table Tricks to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5748" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>2008: Error List in 2008</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx</id><published>2008-03-06T03:40:47Z</published><updated>2008-03-06T03:40:47Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=2008: Error List in 2008&amp;amp;body=Seen on SQLblog.com: %0A%0A%092008: Error List in 2008%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx" target="_blank" title = "Email 2008: Error List in 2008"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx&amp;amp;title=2008%3a+Error+List+in+2008" target="_blank" title = "Submit 2008: Error List in 2008 to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx&amp;amp;phase=2" target="_blank" title = "Submit 2008: Error List in 2008 to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx&amp;amp;title=2008%3a+Error+List+in+2008" target="_blank" title = "Submit 2008: Error List in 2008 to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx&amp;amp;title=2008%3a+Error+List+in+2008" target="_blank" title = "Submit 2008: Error List in 2008 to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/05/2008-error-list-in-2008.aspx&amp;amp;title=2008%3a+Error+List+in+2008&amp;amp;;top=1" target="_blank" title = "Add 2008: Error List in 2008 to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5474" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author><category term="SQL Server" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx" /><category term="SQL Tools" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Tools/default.aspx" /><category term="SSMS" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SSMS/default.aspx" /></entry><entry><title>2008: Declaring and instantiating a value</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx</id><published>2008-03-02T00:40:00Z</published><updated>2008-03-02T00:40:00Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=2008: Declaring and instantiating a value&amp;amp;body=Seen on SQLblog.com: %0A%0A%092008: Declaring and instantiating a value%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx" target="_blank" title = "Email 2008: Declaring and instantiating a value"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx&amp;amp;title=2008%3a+Declaring+and+instantiating+a+value" target="_blank" title = "Submit 2008: Declaring and instantiating a value to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx&amp;amp;phase=2" target="_blank" title = "Submit 2008: Declaring and instantiating a value to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx&amp;amp;title=2008%3a+Declaring+and+instantiating+a+value" target="_blank" title = "Submit 2008: Declaring and instantiating a value to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx&amp;amp;title=2008%3a+Declaring+and+instantiating+a+value" target="_blank" title = "Submit 2008: Declaring and instantiating a value to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/03/01/2008-declaring-and-instantiating-a-value.aspx&amp;amp;title=2008%3a+Declaring+and+instantiating+a+value&amp;amp;;top=1" target="_blank" title = "Add 2008: Declaring and instantiating a value to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5390" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author><category term="SQL Server" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx" /><category term="T-SQL" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx" /></entry><entry><title>2008: Rebuilding a Heap</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx</id><published>2008-02-27T04:10:24Z</published><updated>2008-02-27T04:10:24Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=2008: Rebuilding a Heap&amp;amp;body=Seen on SQLblog.com: %0A%0A%092008: Rebuilding a Heap%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx" target="_blank" title = "Email 2008: Rebuilding a Heap"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx&amp;amp;title=2008%3a+Rebuilding+a+Heap" target="_blank" title = "Submit 2008: Rebuilding a Heap to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx&amp;amp;phase=2" target="_blank" title = "Submit 2008: Rebuilding a Heap to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx&amp;amp;title=2008%3a+Rebuilding+a+Heap" target="_blank" title = "Submit 2008: Rebuilding a Heap to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx&amp;amp;title=2008%3a+Rebuilding+a+Heap" target="_blank" title = "Submit 2008: Rebuilding a Heap to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2008/02/26/2008-rebuilding-a-heap.aspx&amp;amp;title=2008%3a+Rebuilding+a+Heap&amp;amp;;top=1" target="_blank" title = "Add 2008: Rebuilding a Heap to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5295" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author><category term="SQL Server" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx" /><category term="T-SQL" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx" /><category term="Dynamic Management Objects" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/Dynamic+Management+Objects/default.aspx" /></entry><entry><title>2008: Initializing Table Data with Row Constructors</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx</id><published>2007-12-06T01:50:44Z</published><updated>2007-12-06T01:50:44Z</updated><content type="html">&lt;p&gt;Well, I am just discovering this feature, mostly because I never saw it demoed at any of the sessions I have attended so far on 2008.&amp;nbsp; Not that it was kept particularly hidden, I have seen the title before, but I hadn't tried it out, or seen the depth that they have "finally" implemented.&lt;/p&gt; &lt;p&gt;Tonight, I am working on my chapter where I create some tables as part of a big example, and I had the code from the 2005 version of the book (and I add the primary key to the table later in the book, as well as other constraints, so don't judge me!):&lt;/p&gt; &lt;p&gt;CREATE TABLE Inventory.MovieRating (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MovieRatingId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int NOT NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Code&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; varchar(20) NOT NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description&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; varchar(200) NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AllowYouthRentalFlag bit NOT NULL&lt;br&gt;)&lt;br&gt;GO&lt;/p&gt; &lt;p&gt;INSERT INTO Inventory.MovieRating (MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUES (0, 'UR','Unrated',1)&lt;br&gt;INSERT INTO Inventory.MovieRating (MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUE&amp;nbsp;&amp;nbsp; (1, 'G','General Audiences',1),&lt;br&gt;INSERT INTO Inventory.MovieRating (MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUES (2, 'PG','Parental Guidance',1),&lt;br&gt;INSERT INTO Inventory.MovieRating(MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUES (3, 'PG-13','Parental Guidance for Children Under 13',1),&lt;br&gt;INSERT INTO Inventory.MovieRating(MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUES (4, 'R','Restricted, No Children Under 17 without Parent',0)&lt;/p&gt; &lt;p&gt;(Another variety is to use:&lt;/p&gt; &lt;p&gt;INSERT INTO Inventory.MovieRating (MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;SELECT 0, 'UR','Unrated',1&lt;br&gt;UNION ALL&lt;br&gt;SELECT 1, 'G','General Audiences',1&lt;br&gt;UNION ALL&lt;br&gt;SELECT 3, 'PG-13','Parental Guidance for Children Under 13',1&lt;br&gt;UNION ALL&lt;br&gt;SELECT 4, 'R','Restricted, No Children Under 17 without Parent',0&lt;/p&gt; &lt;p&gt;But that is not that much better (certainly a little better).&amp;nbsp; I felt for the book that using VALUES was the more "proper" way to do it.&amp;nbsp; However, now, in the 2008 edition, I obviously have to change &lt;em&gt;all &lt;/em&gt;of the code to use the latest and greatest syntax, so I use row constructors, and this turns into:&lt;/p&gt; &lt;p&gt;INSERT INTO Inventory.MovieRating (MovieRatingId, Code, Description, AllowYouthRentalFlag)&lt;br&gt;VALUES (0, 'UR','Unrated',1),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (1, 'G','General Audiences',1),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2, 'PG','Parental Guidance',1),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (3, 'PG-13','Parental Guidance for Children Under 13',1),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (4, 'R','Restricted, No Children Under 17 without Parent',0)&lt;/p&gt; &lt;p&gt;And it just strikes me at how...simple this is, and how readable this is.&amp;nbsp; I know I have typed the UNION ALL stuff hundreds, possibly thousands (well hundreds more like) of times in the forums over the past year and a half dummying up data for someone who was asking for help but couldn't take the time to do it for us.&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=2008: Initializing Table Data with Row Constructors&amp;amp;body=Seen on SQLblog.com: %0A%0A%092008: Initializing Table Data with Row Constructors%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx" target="_blank" title = "Email 2008: Initializing Table Data with Row Constructors"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx&amp;amp;title=2008%3a+Initializing+Table+Data+with+Row+Constructors" target="_blank" title = "Submit 2008: Initializing Table Data with Row Constructors to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx&amp;amp;phase=2" target="_blank" title = "Submit 2008: Initializing Table Data with Row Constructors to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx&amp;amp;title=2008%3a+Initializing+Table+Data+with+Row+Constructors" target="_blank" title = "Submit 2008: Initializing Table Data with Row Constructors to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx&amp;amp;title=2008%3a+Initializing+Table+Data+with+Row+Constructors" target="_blank" title = "Submit 2008: Initializing Table Data with Row Constructors to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/2008-initializing-table-data-with-row-constructors.aspx&amp;amp;title=2008%3a+Initializing+Table+Data+with+Row+Constructors&amp;amp;;top=1" target="_blank" title = "Add 2008: Initializing Table Data with Row Constructors to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3724" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>Changing the owner of a database</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx</id><published>2007-12-05T05:06:46Z</published><updated>2007-12-05T05:06:46Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Changing the owner of a database&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Changing the owner of a database%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx" target="_blank" title = "Email Changing the owner of a database"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx&amp;amp;title=Changing+the+owner+of+a+database" target="_blank" title = "Submit Changing the owner of a database to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx&amp;amp;phase=2" target="_blank" title = "Submit Changing the owner of a database to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx&amp;amp;title=Changing+the+owner+of+a+database" target="_blank" title = "Submit Changing the owner of a database to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx&amp;amp;title=Changing+the+owner+of+a+database" target="_blank" title = "Submit Changing the owner of a database to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/12/05/changing-the-owner-of-a-database.aspx&amp;amp;title=Changing+the+owner+of+a+database&amp;amp;;top=1" target="_blank" title = "Add Changing the owner of a database to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3690" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author><category term="SQL Server" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx" /><category term="T-SQL" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/T-SQL/default.aspx" /></entry><entry><title>sys.dm_exec_xml_handles</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx</id><published>2007-11-04T20:53:59Z</published><updated>2007-11-04T20:53:59Z</updated><content type="html">&lt;p&gt;d Gives you information about any sessions that are using xml documents, including stats about the XML document and usage.&amp;nbsp; You can also get the statements that were used to create the XML handle using sys.dm_exec_sql_text to get the sql.  &lt;p&gt;&lt;b&gt;Type:&lt;/b&gt; Function&lt;br&gt;&lt;b&gt;Parameter: &lt;/b&gt;session_id&lt;br&gt;&lt;b&gt;Data:&lt;/b&gt; Snapshot, values based on current reality&lt;br&gt;&lt;b&gt;Columns:&lt;/b&gt;  &lt;ul&gt; &lt;li&gt;&lt;b&gt;session_id&lt;/b&gt; - the session_id of the user who is using the sp_xml_preparedocument command to use the XML datatype  &lt;li&gt;&lt;b&gt;document_id&lt;/b&gt; – handle created for the document  &lt;li&gt;&lt;b&gt;namespace_document_id&lt;/b&gt; – you can use sp_xml_preparedocument to declare a document that is&amp;nbsp; namespace, then use it for subsequent calls. This value will have the value of a document_id, or a NULL if there is not one declared  &lt;li&gt;&lt;b&gt;sql_handle&lt;/b&gt; – relates to sys.dm_exec_sql_text to get the T-SQL of the query  &lt;li&gt;&lt;b&gt;statement_start_offset&lt;/b&gt; - the starting point in the T-SQL query object that is currently executing (note that these values are double the expected values due to unicode values. You will have to divide by 2 when using them in equations. For more information, see examples)  &lt;li&gt;&lt;b&gt;statement_end_offset&lt;/b&gt; - the ending point in the T-SQL query object that is currently executing  &lt;li&gt;&lt;b&gt;creation_time&lt;/b&gt; - the time the handle was created  &lt;li&gt;&lt;b&gt;original_document_size_bytes&lt;/b&gt; – size of the original text of the XML document  &lt;li&gt;&lt;b&gt;original_namespace_document_size_bytes - &lt;/b&gt;size of the original text of the XML namespace document&lt;b&gt;&lt;/b&gt;  &lt;li&gt;&lt;b&gt;num_openxml_calls&lt;/b&gt; - Number of times the document has been used in OPENXML calls using this handle  &lt;li&gt;&lt;b&gt;row_count&lt;/b&gt; - Number of rows that have been returned using this handle in OPENXML calls  &lt;li&gt;&lt;b&gt;dormant_duration_ms&lt;/b&gt; - the amount of time (in milliseconds) since the last use of the handle in an OPENXML call&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;b&gt;Example:&lt;/b&gt;  &lt;p&gt;DECLARE @idoc int&lt;br&gt;DECLARE @doc varchar(1000)&lt;br&gt;&lt;br&gt;SET @doc ='&lt;br&gt;&amp;lt;root&amp;gt;&lt;br&gt;&amp;lt;person firstName="barney" lastName="rubble"/&amp;gt;&lt;br&gt;&amp;lt;person firstName="fred" lastName="flintstone"/&amp;gt;&lt;br&gt;&amp;lt;/root&amp;gt;'&lt;br&gt;&lt;br&gt;--Create an internal representation of the XML document.&lt;br&gt;EXEC sp_xml_preparedocument @idoc OUTPUT, @doc &lt;/p&gt; &lt;p&gt;-- Execute a SELECT statement that uses the OPENXML rowset provider. &lt;br&gt;SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp; *&lt;br&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OPENXML (@idoc, '/root/person',1)&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; WITH (firstName varchar(20),&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;&amp;nbsp;&amp;nbsp; lastName varchar(20))  &lt;p&gt;Then you can see the information for this document using:  &lt;p&gt;select *, text, substring(text,statement_start_offset /2,&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; 1+ statement_end_offset/2 - statement_start_offset/2),&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; statement_start_offset,statement_end_offset&lt;br&gt;from&amp;nbsp;&amp;nbsp;&lt;strong&gt; sys.dm_exec_xml_handles(null)&lt;/strong&gt;&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; cross apply sys.dm_exec_sql_text(sql_handle)&lt;/p&gt; &lt;p&gt;&lt;em&gt;Note:&amp;nbsp; This is part of an ongoing project to write a book about all of the dynamic management views for &lt;/em&gt;&lt;a href="http://www.red-gate.com/"&gt;&lt;em&gt;Red-Gate&lt;/em&gt;&lt;/a&gt;&lt;em&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 have begun maintaining the following web page once the book is closer to completion: &lt;/em&gt;&lt;a href="http://drsql.org/dmvbook.aspx"&gt;&lt;em&gt;http://drsql.org/dmvbook.aspx&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, including a list of resources I have used to write the book so far.&lt;/em&gt;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=sys.dm_exec_xml_handles&amp;amp;body=Seen on SQLblog.com: %0A%0A%09sys.dm_exec_xml_handles%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx" target="_blank" title = "Email sys.dm_exec_xml_handles"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx&amp;amp;title=sys.dm_exec_xml_handles" target="_blank" title = "Submit sys.dm_exec_xml_handles to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx&amp;amp;phase=2" target="_blank" title = "Submit sys.dm_exec_xml_handles to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx&amp;amp;title=sys.dm_exec_xml_handles" target="_blank" title = "Submit sys.dm_exec_xml_handles to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx&amp;amp;title=sys.dm_exec_xml_handles" target="_blank" title = "Submit sys.dm_exec_xml_handles to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/11/04/sys-dm-exec-xml-handles.aspx&amp;amp;title=sys.dm_exec_xml_handles&amp;amp;;top=1" target="_blank" title = "Add sys.dm_exec_xml_handles to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3211" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>Normalization's other little side effect...</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx</id><published>2007-10-07T18:56:53Z</published><updated>2007-10-07T18:56:53Z</updated><content type="html">&lt;p&gt;It isn't that I don't like a challenge, really it isn't.&amp;nbsp; I like puzzles, mazes, Suduko, video games with challenging levels where I have to really think about a problem to solve it.&amp;nbsp; So why don't I like poorly&amp;nbsp;designed databases, where finding a value that you want can be just as challenging, or maybe more?&amp;nbsp; Glad you asked (or maybe you didn't, what do I care, this is my blog :)&amp;nbsp;&amp;nbsp; And for any of you who might be asking: "Shouldn't I be able to use SQL Server like I want to?"&amp;nbsp;&amp;nbsp;It is a good thing you didn't actually ask that out loud, or&amp;nbsp;I would have to ban you :)&lt;/p&gt; &lt;p&gt;When someone creates a puzzle, maze, or video game, they design in the challenge purposefully.&amp;nbsp; &lt;a href="http://www.windowsitpro.com/Authors/AuthorID/638/638.html" target="_blank"&gt;Itzik Ben-Gan&lt;/a&gt;&amp;nbsp;frequently sets up SQL puzzles on SQL Server Magazine that can be kind of fun.&amp;nbsp; But when someone builds a poorly designed database, then don't leave you breadcrumbs to find your way around.&amp;nbsp; Quite the opposite.&amp;nbsp; If they had spent time trying to think about how other people might get around in their database, they would have naturally started normalizing.&amp;nbsp;&amp;nbsp; No, usually a poorly designed database is an act of "selfishness" or "ignorance" by a person who is not thinking at all.&amp;nbsp; Or even worse, was.&lt;/p&gt; &lt;p&gt;This all comes up because I spent a good amount of my week this week digging through a database.&amp;nbsp;First I would identify some data, go back to some other people with some knowledge of the data, have a meeting, then go back and try again.&amp;nbsp;&amp;nbsp; What&amp;nbsp;should have been a quick, painless task to identify 20 columns from this database took much longer than necessary.&amp;nbsp; Not 100s of tables worth, no, just a few measly columns.&amp;nbsp; So what was wrong?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Columns that had meaning in one row, but not another&lt;/li&gt; &lt;li&gt;Columns named FieldName1, FieldName2...&lt;/li&gt; &lt;li&gt;Two related tables that were not related by key, but by a concatenation of columns&lt;/li&gt; &lt;li&gt;One database per day of activity, not a key that denotes a different day&lt;/li&gt; &lt;li&gt;Data with embedded values, and not always the same format.&amp;nbsp; &lt;/li&gt; &lt;li&gt;Domain value with no apparent meaning&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I could go on, but I would just be making stuff up.&amp;nbsp; And frankly this is enough mess for a Sunday afternoon.&amp;nbsp; The problem is, had someone taken the time to design this database using proper normalization techniques, none of these problems would be evident.&amp;nbsp; So what is the side effect?&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Documentation&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Not that it is impossible to build an incomprehensible normalized database (lots of companies do stuff to make it hard for competitors to understand their data (like having column names be non-sensical without their data dictionary).&amp;nbsp; But the problem here is that yet another person spent time creating a "general purpose" database.&amp;nbsp; It never ceases to amaze me the lengths that people will go to never change tables in SQL.&amp;nbsp; So they do all of this nasty mapping in their code.&amp;nbsp; &lt;/p&gt; &lt;p&gt;But you know what.&amp;nbsp; It turns out that SQL Server has a lot of really cool stuff that lets you customize data storage.&amp;nbsp; For example:&lt;/p&gt; &lt;p&gt;ALTER TABLE allows you to add columns&lt;/p&gt; &lt;p&gt;CREATE TABLE allows you to create tables&lt;/p&gt; &lt;p&gt;sp_addextendedproperty allows you to add documentation to these properties&lt;/p&gt; &lt;p&gt;Note that I am not necessarily suggesting that the answer to all "open schema" type problems necessarily should&amp;nbsp;(or even could) be solved by simply adding to the schema.&amp;nbsp; In many cases you would not want that at all.&amp;nbsp; But in this case, I am not talking about that situation.&amp;nbsp; Why?&amp;nbsp; Because the code had to change...&lt;/p&gt; &lt;p&gt;If the code that accesses the data needs to change based on the structure, extend the data structures.&amp;nbsp; It will&amp;nbsp;save you code if your database is cleanly created and normalized. &amp;nbsp;&lt;strong&gt;&lt;em&gt;Use SQL to do the job it was made for.&lt;/em&gt;&lt;/strong&gt;&amp;nbsp; Then, it will be easy to go to one table that has a name that matches what I think I want, see what it is used for, then go to related tables, and to their related tables and so on.&amp;nbsp; Legal values for a column will be documented and checked.&amp;nbsp; Names given to columns will reflect their meaning.&amp;nbsp; You might even have descriptions stored in extended properties.&lt;/p&gt; &lt;p&gt;And then a job that took a week could have taken an hour.&amp;nbsp; (On the other hand, I get another anecdote for my presentation next weekend at devlink (&lt;a href="http://www.devlink.com"&gt;www.devlink.com&lt;/a&gt;) and for my next book.&amp;nbsp; And this blog.&amp;nbsp; Maybe I do like poorly normalized databases...Nah!)&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Normalization's other little side effect...&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Normalization's other little side effect...%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx" target="_blank" title = "Email Normalization's other little side effect..."&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx&amp;amp;title=Normalization%27s+other+little+side+effect..." target="_blank" title = "Submit Normalization's other little side effect... to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx&amp;amp;phase=2" target="_blank" title = "Submit Normalization's other little side effect... to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx&amp;amp;title=Normalization%27s+other+little+side+effect..." target="_blank" title = "Submit Normalization's other little side effect... to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx&amp;amp;title=Normalization%27s+other+little+side+effect..." target="_blank" title = "Submit Normalization's other little side effect... to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/07/normalization-s-other-little-side-effect.aspx&amp;amp;title=Normalization%27s+other+little+side+effect...&amp;amp;;top=1" target="_blank" title = "Add Normalization's other little side effect... to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2898" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>sys.dm_exec_sql_text</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx</id><published>2007-10-04T03:53:26Z</published><updated>2007-10-04T03:53:26Z</updated><content type="html">&lt;p&gt;&lt;em&gt;(Edit: Was reading Adam's book tonight and discovered you can pass a plan handle to this object.&amp;nbsp; Very interesting!)&lt;/em&gt; &lt;p&gt;This dynamic management object returns the SQL that was saved when a query was executed. This is a very exciting and useful thing to have, as there are dynamic management views that you will be able to use to get statistics for a query, as well as the full SQL for any actively executing query.  &lt;p&gt;This is a tremendous leap ahead of the functionality that was available via the rather limited view available from DBCC INPUTBUFFER, where we could only get the first 256 characters. Be careful on active servers with very large queries as this can return a lot of data.  &lt;p&gt;&lt;b&gt;Type:&lt;/b&gt; Function  &lt;p&gt;&lt;b&gt;Parameter: &lt;/b&gt; &lt;ul&gt; &lt;li&gt;&lt;b&gt;handle (either one of the following types)&lt;/b&gt;&lt;/li&gt; &lt;ul&gt; &lt;li&gt;&lt;b&gt;sql_handle&lt;/b&gt; – ( which can be retrieved from sys.dm_exec_query_stats, sys.dm_exec_requests, sys.dm_exec_cursors, sys.dm_exec_xml_handles, sys.dm_exec_query_memory_grants)&lt;/li&gt; &lt;li&gt;&lt;b&gt;plan_handle - &lt;/b&gt;( which can be retrieved sys.dm_exec_requests, sys.dm_exec_query_memory_grants, sys.dm_exec_query_stats, sys.dm_exec_cached_plan)&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;&lt;b&gt;Data:&lt;/b&gt; Snapshot, values based on current reality. Note that rows can be reset by running DBCC FREEPOCCACHE, removing all rows from the query cache.  &lt;p&gt;&lt;b&gt;Columns:&lt;br&gt;&lt;/b&gt; &lt;ul&gt; &lt;li&gt;&lt;b&gt;&lt;i&gt;Grouping:&lt;/i&gt;&lt;/b&gt;&lt;i&gt; &lt;b&gt;Object Reference&lt;/b&gt; &lt;/i&gt;If the query is executing an object, the following three columns will give you the pointer to the object. They will be NULL when you are executing a batch of SQL Statements.  &lt;ul&gt; &lt;li&gt;&lt;b&gt;dbid &lt;/b&gt;- surrogate key for the database, if applicable. (Note: this is usually database_id in other objects. Look for this to change in a following version)  &lt;li&gt;&lt;b&gt;objectid &lt;/b&gt;- surrogate key for the object in a database, if applicable. (Note: this is usually object_id in other objects. Look for this to change in a following version)  &lt;li&gt;&lt;b&gt;number – &lt;/b&gt;for stored procedures, can be the number for grouped procedures. Proc;1, Proc;2. Rarely used.&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;&lt;b&gt;encrypted&lt;/b&gt; – 1 if plan is encrypted, which will prevent viewing of the query text. 0 otherwise.  &lt;li&gt;&lt;b&gt;text &lt;/b&gt;– The text of the query, unless the object is encrypted, in which case it will be NULL&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;b&gt;Example:&lt;/b&gt;  &lt;p&gt;See the query you are executing:  &lt;p&gt;select dest.*&lt;br&gt;from&amp;nbsp; sys.dm_exec_requests as der&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; cross apply sys.dm_exec_sql_text (der.sql_handle) as dest&lt;br&gt;where session_id = @@spid  &lt;p&gt;This&amp;nbsp;will return:  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;dbid&amp;nbsp;&amp;nbsp; objectid&amp;nbsp;&amp;nbsp;&amp;nbsp; number encrypted &lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;------ ----------- ------ --------- &lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;NULL&amp;nbsp;&amp;nbsp; NULL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NULL&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;/font&gt;  &lt;p&gt;&lt;font face="Courier New" size="2"&gt;text&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;-----------------------------------------&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;select dest.*&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;from&amp;nbsp;&amp;nbsp; sys.dm_exec_requests as der&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cross apply sys.dm_exec_sql_text (der.sql_handle) as dest&lt;br&gt;&lt;/font&gt;&lt;font face="Courier New" size="2"&gt;where session_id = @@spid&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Of course, that is kind of a silly query, but it is a repeatable result that you can execute to see how the function works. The&amp;nbsp;sys.dm_exec_sql_text object will actually be of a lot more use when it is used by other dynamic management objects that have a query handle (sys.dm_exec_query_stats, sys.dm_exec_requests, sys.dm_exec_cursors, sys.dm_exec_xml_handles, sys.dm_exec_query_memory_grants)  &lt;p&gt;&amp;nbsp;  &lt;p&gt;&lt;em&gt;Note:&amp;nbsp; This is part of an ongoing project to write a book about all of the dynamic management views for &lt;/em&gt;&lt;a href="http://www.red-gate.com/"&gt;&lt;em&gt;Red-Gate&lt;/em&gt;&lt;/a&gt;&lt;em&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;/em&gt;&lt;a href="http://drsql.org/dmvbook.aspx"&gt;&lt;em&gt;http://drsql.org/dmvbook.aspx&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=sys.dm_exec_sql_text&amp;amp;body=Seen on SQLblog.com: %0A%0A%09sys.dm_exec_sql_text%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx" target="_blank" title = "Email sys.dm_exec_sql_text"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx&amp;amp;title=sys.dm_exec_sql_text" target="_blank" title = "Submit sys.dm_exec_sql_text to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx&amp;amp;phase=2" target="_blank" title = "Submit sys.dm_exec_sql_text to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx&amp;amp;title=sys.dm_exec_sql_text" target="_blank" title = "Submit sys.dm_exec_sql_text to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx&amp;amp;title=sys.dm_exec_sql_text" target="_blank" title = "Submit sys.dm_exec_sql_text to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/10/03/sys-dm-exec-sql-text.aspx&amp;amp;title=sys.dm_exec_sql_text&amp;amp;;top=1" target="_blank" title = "Add sys.dm_exec_sql_text to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2859" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry><entry><title>PASS Followup, Technical Edition</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx</id><published>2007-09-25T05:03:00Z</published><updated>2007-09-25T05:03:00Z</updated><content type="html">&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=PASS Followup, Technical Edition&amp;amp;body=Seen on SQLblog.com: %0A%0A%09PASS Followup, Technical Edition%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx" target="_blank" title = "Email PASS Followup, Technical Edition"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx&amp;amp;title=PASS+Followup%2c+Technical+Edition" target="_blank" title = "Submit PASS Followup, Technical Edition to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx&amp;amp;phase=2" target="_blank" title = "Submit PASS Followup, Technical Edition to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx&amp;amp;title=PASS+Followup%2c+Technical+Edition" target="_blank" title = "Submit PASS Followup, Technical Edition to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx&amp;amp;title=PASS+Followup%2c+Technical+Edition" target="_blank" title = "Submit PASS Followup, Technical Edition to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/09/25/pass-followup-technical-edition.aspx&amp;amp;title=PASS+Followup%2c+Technical+Edition&amp;amp;;top=1" target="_blank" title = "Add PASS Followup, Technical Edition to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2668" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author><category term="SQL Server" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/SQL+Server/default.aspx" /><category term="PASS" scheme="http://sqlblog.com/blogs/louis_davidson/archive/tags/PASS/default.aspx" /></entry><entry><title>DMV Progress and Upcoming Events (PASS/Devlink)</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx" /><id>http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx</id><published>2007-08-26T20:52:00Z</published><updated>2007-08-26T20:52:00Z</updated><content type="html">&lt;P&gt;If you have noticed my series of posts on the DMV's on &lt;A href="http://sqlblog.com/blogs/louis_davidson"&gt;http://sqlblog.com/blogs/louis_davidson&lt;/A&gt;, you may have wondered why these posts are coming so slowly.&amp;nbsp; I mean, if I am actually going to get a book of all of them, with examples, done in a couple of months, I certainly had better be further along than I seem to be.&lt;/P&gt;
&lt;P&gt;Thankfully, I &lt;EM&gt;&lt;STRONG&gt;am&lt;/STRONG&gt;&lt;/EM&gt; farther along than this.&amp;nbsp; The problem is that I just don't have any others done to the level that I feel merits being posted.&amp;nbsp; On the bright side, the DMV's are really quite amazing for their depth.&amp;nbsp; On the down side, the DMV's are really quite amazing for their depth.&amp;nbsp; There are many many many columns returned, and some of them are still not really clear enough for me to post.&amp;nbsp; So I am going back and forth over and over trying to get all of the columns understood enough to write about them.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlpass.org/"&gt;&lt;IMG id=ctl00_PASSLogo style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;WIDTH:133px;HEIGHT:74px;BORDER-RIGHT-WIDTH:0px;" alt="PASS Home" src="https://www.sqlpass.org/sitecollectionimages/SiteImages/logo.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The PASS Community Summit is coming up quick.&amp;nbsp; I will be there working on the opening day(s) for some training and the Quizbowl (this year is hopefully Jeopardy for nerds.&amp;nbsp; Email me at &lt;A href="mailto:drsql@hotmail.com"&gt;drsql@hotmail.com&lt;/A&gt; if you want a chance to possibly be a contestant.)&amp;nbsp;&amp;nbsp; I will be at the conference for the rest of the week learning and chilling out.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG height=50 src="http://www.devlink.net/Portals/_default/Skins/devlink_main/logo.gif" width=176&gt;&lt;/P&gt;
&lt;P&gt;Finally, on October 13, I will be speaking at the &lt;A href="http://www.devlink.net/" target=_blank&gt;devLink&lt;/A&gt; technical conference in Nashville, TN.&amp;nbsp; It is pretty cool really, and for 50 bucks,&amp;nbsp;a two day conference is a pretty dang good deal (and please no flame comment wars about these two different conferences and money values.&amp;nbsp; I will delete any comments like that :)&amp;nbsp;&amp;nbsp;There are lots of&amp;nbsp;&lt;A href="http://www.devlink.net/Information/Speakers/tabid/80/Default.aspx" target=_blank&gt;good speakers&lt;/A&gt; who will be there, and it is a bit of an honor to speak.&amp;nbsp;I will be giving two presentations, sadly back to back, on Saturday (also kind of sad, as Elvis Costello and Bob Dylan are in Columbus OH, that night), one about the reasons to normalize, and the other about performance tuning.&amp;nbsp; It will be largely 80% a discussion about the dynamic management objects.&amp;nbsp; I plan to do a great amount of example writing for the book in the weeks before the conference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE:&amp;nbsp; If you read my blog, books, etc, please feel free to accost me and tell me what you like or don't like about anything I produce.&amp;nbsp; I really really really want feedback.&amp;nbsp; I am about to start the 2008 edition of my design book, and I want to know what would make you purchase it, either for the first time, or again if you have any of the previous editions.&amp;nbsp; I am not sure that I would purchase each edition myself, so it is one of those things I obsess about.&amp;nbsp; The pay for writing is terrible (horrible, awful, terrible, to be exact) and the reason I do it is for my reference (I search the PDF of my book 2-5 times a month, and my websites 10-30 times a month) and to evangelize good design in my own, very light, sort of style.&amp;nbsp; If you want to schedule lunch to talk, drop me a line and we can get some eats and talk about the book.&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Crossposted to &lt;A href="http://drsql.spaces.live.com/"&gt;http://drsql.spaces.live.com&lt;/A&gt;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=DMV Progress and Upcoming Events (PASS/Devlink)&amp;amp;body=Seen on SQLblog.com: %0A%0A%09DMV Progress and Upcoming Events (PASS/Devlink)%0A%0Ahttp://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx" target="_blank" title = "Email DMV Progress and Upcoming Events (PASS/Devlink)"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx&amp;amp;title=DMV+Progress+and+Upcoming+Events+(PASS%2fDevlink)" target="_blank" title = "Submit DMV Progress and Upcoming Events (PASS/Devlink) to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx&amp;amp;phase=2" target="_blank" title = "Submit DMV Progress and Upcoming Events (PASS/Devlink) to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx&amp;amp;title=DMV+Progress+and+Upcoming+Events+(PASS%2fDevlink)" target="_blank" title = "Submit DMV Progress and Upcoming Events (PASS/Devlink) to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx&amp;amp;title=DMV+Progress+and+Upcoming+Events+(PASS%2fDevlink)" target="_blank" title = "Submit DMV Progress and Upcoming Events (PASS/Devlink) to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/louis_davidson/archive/2007/08/26/dmv-progress-and-upcoming-events-pass-devlink.aspx&amp;amp;title=DMV+Progress+and+Upcoming+Events+(PASS%2fDevlink)&amp;amp;;top=1" target="_blank" title = "Add DMV Progress and Upcoming Events (PASS/Devlink) to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2343" width="1" height="1"&gt;</content><author><name>drsql</name><uri>http://sqlblog.com/members/drsql.aspx</uri></author></entry></feed>