<feed version="0.3" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://purl.org/atom/ns#" xml:lang="en-US"><title>adam machanic now blogs at http://sqlblog.com</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/default.aspx" /><tagline type="text/html">This blog is officially retired.  Please visit http://sqlblog.com.</tagline><id>http://www.sqljunkies.com/WebLog/amachanic/default.aspx</id><author><url>http://www.sqljunkies.com/WebLog/amachanic/default.aspx</url></author><generator url="http://communityserver.org" version="1.0.1.50214">Community Server</generator><modified>2006-11-18T12:56:00Z</modified><entry><title>Goodbye, SQLJunkies!</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/07/08/44965.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:44965</id><created>2007-07-08T11:18:14Z</created><content type="text/html" mode="escaped">&lt;p&gt;A year ago this week, I moved my SQLJunkies blog over to this one, on &lt;a href="http://sqlblog.com"&gt;SQLblog.com&lt;/a&gt;.&amp;nbsp; I decided to cross-post for a while in order to take advantage of the syndication offered by SQLJunkies.&amp;nbsp; At this point, it seems that my SQLblog blog is getting more activity (and better activity), so I'm officially cutting off my cross-posting.&amp;nbsp; Going forward, content will only be posted &lt;a href="http://sqlblog.com/blogs/adam_machanic/default.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Thanks to all of the SQLblog bloggers for helping to create such a great community!&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=44965" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=44965</wfw:commentRss></entry><entry><title>New version of SQLQueryStress released</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/06/28/39612.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:39612</id><created>2007-06-28T02:30:56Z</created><content type="text/html" mode="escaped">&lt;p&gt;Eight months ago &lt;a href="http://sqljunkies.com/blogs/adam_machanic/archive/2006/10/21/327.aspx"&gt;I announced the release&lt;/a&gt; of the first beta version of &lt;a href="http://www.datamanipulation.net/SQLQueryStress/"&gt;SQLQueryStress&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;I had big plans: Collect a bunch of feedback, quickly fix any bugs that came in, and release a final version. Time frame of two weeks, tops.&lt;/p&gt;&lt;p&gt;As is often the case, life interrupted my progress. And so and here I am eight months later releasing not the final version, but rather a &lt;a href="http://www.datamanipulation.net/SQLQueryStress/sqlquerystressdownload.asp"&gt;second beta&lt;/a&gt;. Truth be told, feedback was a lot sparser than I'd hoped, and the bugs ended up being a lot harder to track down and fix.&amp;nbsp; Not that it took me eight months to fix them; I've been working through them on and off only for the last week, and I believe I've tackled most of the major issues that people did bother to report to me.&amp;nbsp; You can find a list of the fixes/enhancements on the download page.&lt;br&gt;&lt;/p&gt;&lt;p&gt;So if you're interested in checking out this new version, &lt;a href="http://www.datamanipulation.net/SQLQueryStress/sqlquerystressdownload.asp"&gt;grab it here&lt;/a&gt;. Please let me know if you see bugs or anything you like, dislike, etc. I have written this program for the community at large, so please feel free to help guide its future development!&lt;br&gt;&lt;/p&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=39612" width="1" height="1"&gt;</content><slash:comments>1</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=39612</wfw:commentRss></entry><entry><title>Database Mirroring: FQDNs are Your Friends!</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/06/13/36749.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:36749</id><created>2007-06-13T21:21:22Z</created><content type="text/html" mode="escaped">&lt;P&gt;On a recent project for a customer, I learned an imporant Database Mirroring lesson:&amp;nbsp;fully-qualified domain names (FQDNs)&amp;nbsp;are &lt;EM&gt;essential&lt;/EM&gt;!&lt;/P&gt;
&lt;P&gt;Both Books Online and the mirroring wizard indicate that it's OK to specify the participating servers as IP addresses--so that's what I did.&amp;nbsp; The witness came up fine, and the principal came up fine.&amp;nbsp; Mirroring started, and I did a few manual failovers.&amp;nbsp; Great!&lt;/P&gt;
&lt;P&gt;But now I added the witness server and suddenly things started breaking down. The mirror instance couldn't connect with the witness, and the witness was throwing strange errors like:&lt;/P&gt;
&lt;P&gt;Database mirroring connection error 4 'An error occurred while receiving data: '64(The specified network name is no longer available.)'.' for 'TCP://Server2:7024'.&lt;/P&gt;
&lt;P&gt;...where "Server2" in this example is the mirror. Notice that the error doesn't include the IP address, but rather the server's name?&lt;/P&gt;
&lt;P&gt;After banging my head against the table for a day or so, I wrote to about 50 people asking for help.&amp;nbsp;No&amp;nbsp;answers, and&amp;nbsp;I thought I was out of luck until &lt;A class="" href="http://www.sqldownunder.com/SDU18FullShow.mp3"&gt;Don Vilen&lt;/A&gt; was kind enough to reply. Turns out, the problem is simple to fix: Don't use IP addresses, ever.&amp;nbsp; Always use FQDNs!&amp;nbsp; Thanks, Don!!&amp;nbsp; Once the FQDNs were used, instead of the IP addresses, everything came up as expected and automatic failovers started working perfectly.&lt;/P&gt;
&lt;P&gt;To find your server's FQDN, you can use "ipconfig" from the command prompt, and append the server name to the connection-specific DNS suffix.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I hope this post helps someone else avoid the frustration I went through.&amp;nbsp;It was a rough couple of days trying to debug this problem and having to tell a customer that their planned&amp;nbsp;HA solution might not work is not a fun situation to be in.&lt;/P&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=36749" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=36749</wfw:commentRss></entry><entry><title>[Editorial] Get rid of the bad apples in IT?</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/05/24/34339.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:34339</id><created>2007-05-24T20:36:52Z</created><content type="text/html" mode="escaped">&lt;P&gt;How many really shoddy developers have you worked with in the last five years?&amp;nbsp; People you wouldn't trust to touch a single line of code, let alone develop some core piece of software upon which the enterprise depends?&lt;/P&gt;
&lt;P&gt;And how difficult is it to &lt;A class="" href="http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1652.entry"&gt;hire a qualified IT pro&lt;/A&gt; these days?&amp;nbsp; Anyone who has done some interviewing recently knows that there are huge masses of unqualified people out there who fake their way into the interview process.&amp;nbsp; How many resumes did you throw out before arriving at those few people that you actually wanted to talk to?&amp;nbsp; And how many of them lived up to their self-proclaimed hype?&lt;/P&gt;
&lt;P&gt;And so I applaud Jerry Fishenden of Microsoft UK, who has suggested that a &lt;A class="" href="http://news.zdnet.com/2100-9588_22-6186364.html?part=rss&amp;amp;tag=feed&amp;amp;subj=zdnn"&gt;real professional body be created for the IT industry&lt;/A&gt;. An organization with the authority to ban people from practicing IT if they're not up to snuff.&amp;nbsp;This would bring our industry in line with other important professions including medical, legal, and other forms of engineering.&amp;nbsp; Yes, the unfortunate truth is that we've all encountered less-than-capable members of these professions as well, but at least there is some semblance of a guarantee there, unlike&amp;nbsp;in IT where you can buy a "certification" for a few hundred dollars to tack onto your resume and there is no clear way of authenticating it.&lt;/P&gt;
&lt;P&gt;Such an organization would not solve all of the problems, and probably wouldn't even solve most of them, but I think it would be a big step in the right direction. IT is a professional trade, and it's time to treat it as such.&lt;/P&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=34339" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=34339</wfw:commentRss></entry><entry><title>Another Webcast Thanks: Errors and Exceptions in SQL Server 2005</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/05/18/33740.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:33740</id><created>2007-05-18T16:08:01Z</created><content type="text/html" mode="escaped">&lt;P&gt;Thank you to everyone who attended today's webcast on &lt;A class="" href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032336451&amp;Culture=en-US"&gt;Errors and Exceptions in SQL Server 2005&lt;/A&gt;!  There were a huge number of excellent questions and I had a really great time talking to you all about what I feel is a very important topic. The webcast is now available for offline viewing, for those who didn't catch it (for shame).&lt;/P&gt;
&lt;P&gt;The contest for the free copy of "&lt;A class="" href="http://www.apress.com/book/bookDisplay.html?bID=10220"&gt;Expert SQL Server 2005&lt;/A&gt;" generated some interesting responses that I wasn't expecting--and I learned a bit about the error messages that I didn't know before!  For those who weren't there, I asked attendees to e-mail me the count of the number of exceptions in sys.messages that are at the highest level of severity.&lt;/P&gt;
&lt;P&gt;When I asked, I expected the correct answer to be 9:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SELECT COUNT(DISTINCT message_id) &lt;BR&gt;FROM sys.messages&lt;BR&gt;WHERE &lt;BR&gt; severity = &lt;BR&gt; (&lt;BR&gt;  SELECT MAX(severity)&lt;BR&gt;  FROM sys.messages&lt;BR&gt; )&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;However, I received quite a range of answers, so I broadened the acceptable pool a bit to include any of the following:&lt;/P&gt;
&lt;P&gt;A) 9, as covered above&lt;/P&gt;
&lt;P&gt;B) 81, or 90, which would result from the following query run on RTM or SP2, respectively (I had no idea that the SP would change the answer here, and I was vague about whether language-specific messages should count):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SELECT COUNT(*) &lt;BR&gt;FROM sys.messages&lt;BR&gt;WHERE &lt;BR&gt; severity = &lt;BR&gt; (&lt;BR&gt;  SELECT MAX(severity)&lt;BR&gt;  FROM sys.messages&lt;BR&gt; )&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;C) 158 or 163, if the query from (A) is run on 2005 RTM or SP2 using severity &gt;= 20, rather than the subquery.  I mentioned in the webcast that anything &gt;= 20 is the highest category of severities in SQL Server, so that's a valid answer--it means you were listening!&lt;/P&gt;
&lt;P&gt;D) 1422 or 1630, if the query from (B) is run on 2005 RTM or SP2 using severity &gt;= 20.&lt;/P&gt;
&lt;P&gt;E) 4, if you told me that you ran the query in SQL Server 2000.&lt;/P&gt;
&lt;P&gt;F) ?  I'm still reading through a few more responses to figure out if I want to add another acceptable answer or two.&lt;/P&gt;
&lt;P&gt;I will write to everyone who entered tomorrow and let you know if a copy is on the way.  Thanks again for attending.&lt;/P&gt;
&lt;P&gt;The code samples used in the session are attached to this post.&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=33740" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=33740</wfw:commentRss></entry><entry><title>DevTeach and a Bunch of News and Links</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/05/16/33356.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:33356</id><created>2007-05-16T11:10:48Z</created><content type="text/html" mode="escaped">&lt;p&gt;I flew to Montreal yesterday morning for the &lt;a href="http://www.devteach.com/"&gt;DevTeach &lt;/a&gt;conference, which was pretty much a whirlwind for me--after getting to the hotel I had only a couple of hours to myself before doing two back-to-back talks (on concurrency and data access architecture), followed by a speaker dinner hosted by the conference at a great restaurant called &lt;a href="http://www.gibbys.com/"&gt;Gibby's&lt;/a&gt;.&amp;nbsp; DevTeach gets my top vote for conference food! After the dinner it was back to my room to write a bit of new material for my talk this morning at 8:00 a.m.&amp;nbsp; A slightly early time slot, but I was just awake enough to not mumble too badly and I think that the audience managed to follow along even without quite enough caffeine intake. And now I'm getting ready to jump on a flight back to Boston. Quite a quick two days!&lt;br&gt;&lt;/p&gt;&lt;p&gt;Aside from the aforementioned victuals, I only have positive praise for the rest of the conference as well.&amp;nbsp; This was my second year there (I had to miss last year due to an injury), and I was very pleasantly surprised by how much better-attended the SQL Server track was than last time I was here.&amp;nbsp; The attendees in my sessions asked some excellent questions, and I left feeling that the overall orientation towards SQL Server is much higher and better put together at DevTeach than at many other conferences that happen to include SQL Server tracks--a testament to the great work done by the conference team.&lt;/p&gt;&lt;p&gt;Starting this November, the conference will be going on the road to Vancouver, so if you live in that area make sure you check it out! I'm sure they'll put on another fantastic show.&lt;/p&gt;&lt;p&gt;&lt;img src="http://www.apress.com/ApressCorporate/supplement/1/10220/bcm.gif" height="164" width="125"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;In other news, &lt;a href="http://www.apress.com/book/bookDisplay.html?bID=10220"&gt;Expert SQL Server 2005 Development is LIVE!!!!&lt;/a&gt;&lt;/p&gt;&lt;p&gt;It's been available on Amazon and Barnes and Noble for a couple of days, but you can now get a sample chapter and view the TOC on the Apress web site.&amp;nbsp;&lt;a href="http://www.apress.com/book/bookDisplay.html?bID=10220"&gt; Go for it!&amp;nbsp;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In conjunction with the release, I did &lt;a href="http://sqlservercode.blogspot.com/2007/05/interview-with-adam-machanic-author-of.html"&gt;an interview with the always interesting Denis the SQL Server Menace&lt;/a&gt;. Check that out if you'd like a bit more information on some of the material I included in the book, as well as some other questions Denis came up with. &lt;/p&gt;&lt;p&gt;There is also &lt;a href="http://www.code-magazine.com/Article.aspx?quickid=0705051"&gt;an article online that I did for CoDe Magazine&lt;/a&gt;, which uses some of the same examples as the book's SQLCLR design chapter. And if you want even more, I have &lt;a href="http://simple-talk.com/sql/t-sql-programming/a-primer-on-managing-data-bitemporally/"&gt;a book extract from the chapter on Temporal data currently live on Simple-Talk.com&lt;/a&gt;.&amp;nbsp; And if you're in the UK and you subscribe to &lt;a href="http://www.vsj.co.uk/"&gt;VSJ&lt;/a&gt;, you can see a book extract from another section of the Temporal data chapter, which will be published in next month's issue.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Enjoy, and thanks for reading!&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=33356" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=33356</wfw:commentRss></entry><entry><title>Thank you for attending today's webcast on Authorization, Privilege, and Access Control</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/05/11/32928.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:32928</id><created>2007-05-11T17:15:04Z</created><content type="text/html" mode="escaped">&lt;P&gt;Thanks to everyone who attended today's MSDN webcast on Authorization, Privilege, and Access Control in SQL Server 2005. There were a lot of really great questions, and it was fun to be able to share a few insights into how to protect your data!&lt;/P&gt;
&lt;P&gt;Several people asked for the code, so it is attached to this post.  Feel free to leave me a comment if you have any questions or need some help with it.&lt;/P&gt;
&lt;P&gt;For those who did not attend the webcast, you can still view it on demand, &lt;A class="" href="http://msevents.microsoft.com/cui/eventdetail.aspx?eventID=1032334738&amp;Culture=en-US"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;And finally, thanks to all who entered into the raffle for a free copy of "&lt;A class="" href="http://www.amazon.com/Expert-SQL-Server-2005-Development/dp/159059729X"&gt;Expert SQL Server 2005 Development&lt;/A&gt;!"  Congrats to the winners, Kong Li, Igor Deck, and Steve Horth.  For those who did not win, no worries--I'll be doing another contest next week in my MSDN webcast on &lt;A class="" href="http://msevents.microsoft.com/cui/eventdetail.aspx?eventID=1032336451&amp;Culture=en-US"&gt;Errors and Exceptions in SQL Server 2005&lt;/A&gt;.  See you there!&lt;/P&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=32928" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=32928</wfw:commentRss></entry><entry><title>Upcoming speaking engagements</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/05/08/32637.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:32637</id><created>2007-05-08T10:56:58Z</created><content type="text/html" mode="escaped">&lt;P&gt;The next two weeks are going to be extremely busy for me, with a few different speaking engagements.&amp;nbsp;I'm not sure why these always seem to come in clumps rather than being spread out a bit more, but I guess at least that way I can get them all taken care of at once!&lt;/P&gt;
&lt;P&gt;Anyway, here's what's going on:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Wednesday, May 9: I'll be speaking at the &lt;A class="" href="http://www.snessug.org/"&gt;Southern New England SQL Server Users Group&lt;/A&gt; in Warwick, RI. The topic of my talk is &lt;STRONG&gt;building highly concurrent database applications&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Friday, May 11: I'll be doing an &lt;STRONG&gt;MSDN Webcast&lt;/STRONG&gt; on &lt;A class="" href="http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032334738"&gt;Authorization, Privilege, and Access Control in SQL Server 2005&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;Tuesday and Wednesday, May 15 and 16: Back to Montreal for &lt;A class="" href="http://www.devteach.com/"&gt;DevTeach&lt;/A&gt;! This year I'll be doing three sessions. The same &lt;STRONG&gt;highly concurrent database applications&lt;/STRONG&gt; talk I'm doing at the SNE group on Wednesday, a talk on &lt;STRONG&gt;architecting for data access&lt;/STRONG&gt;, and a talk on &lt;STRONG&gt;graphs and hierarchies&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Friday, May 18: A second &lt;STRONG&gt;MSDN Webcast&lt;/STRONG&gt;. This time the topic is &lt;A class="" href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032336451"&gt;Errors and Exceptions in SQL Server 2005&lt;/A&gt;.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;All of these talks are based--at least in part--on material from my almost-released book, "&lt;A class="" href="http://www.amazon.com/Expert-SQL-Server-2005-Development/dp/159059729X"&gt;Expert SQL Server 2005 Development&lt;/A&gt;". The book will ship on May 21. Stay tuned to this blog or any of my speaking events for information on how you can win a free copy!&lt;/P&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=32637" width="1" height="1"&gt;</content><slash:comments>2</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=32637</wfw:commentRss></entry><entry><title>[Nontechnical] Various updates</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/03/04/28746.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:28746</id><created>2007-03-04T13:31:43Z</created><content type="text/html" mode="escaped">&lt;p&gt;Things have been silent here on my blog for almost two months, and for that I apologize.&amp;nbsp; I've been extremely busy, but luckily am starting to dig out and hope to see the light of day soon.&lt;/p&gt;&lt;p&gt;I am ever-so-close to being finished with my new book, &lt;a href="http://www.amazon.com/Expert-SQL-Server-2005-Development/dp/159059729X/ref=pd_bbs_sr_1/103-2814051-2415053?ie=UTF8&amp;amp;s=books&amp;amp;qid=1173031916&amp;amp;sr=8-1"&gt;Expert SQL Server 2005 Development&lt;/a&gt;, which will ship in May rather than March as Amazon currently shows (but you can preorder if you want!&amp;nbsp; be the first one in your office to get a copy!!)&amp;nbsp; All the writing is done now, and we just have a bit of tech review and copy editing to finish up before it's a done deal.&amp;nbsp; I'm really excited for this book, and will publish the TOC and a sample chapter here as soon as they become available to me. &lt;/p&gt;&lt;p&gt;In February, I did quite a bit of speaking.&amp;nbsp; First I spoke at the &lt;a href="http://www.nesql.org/default.aspx"&gt;New England SQL Server Users Group&lt;/a&gt;, then I flew to Montreal to speak at the &lt;a href="http://www.guvsm.net/"&gt;Groupe d'usagers Visual Studio &lt;/a&gt;&lt;span id="dnn_ctr380_dnnTITLE_lblTitle" class="XDMBlue"&gt;&lt;a href="http://www.guvsm.net/"&gt;Montréal&lt;/a&gt;, a great group run by &lt;a href="http://www.devteach.com/"&gt;Jean-Rene Roy&lt;/a&gt; and a few .NET MVPs.&amp;nbsp; Jean-Rene also drove me to Ottawa so that I could speak at the &lt;a href="http://www.ottawacommunity.net/"&gt;Ottawa .NET Community&lt;/a&gt;, another very well-run group!&amp;nbsp; After getting stranded in Montreal for two days because of the major snowstorm that hit that week, I have to say that I will think twice before using United Airlines again.&amp;nbsp; I flew to Montreal on an Air Canada partner ticket, and it was amazing how badly I was treated by United's customer service people.&amp;nbsp; I finally flipped the ticket over to Air Canada, whose service people quickly proved that they have some conception of how to treat a customer.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;I was not back in Boston for too long before it was time to fly out again, this time to London for the &lt;a href="http://www.devweek.com/"&gt;DevWeek / SQL Server DevCon&lt;/a&gt; conference. This was a really great few days!&amp;nbsp; I'd never been to London before, and luckily got some time to see a few attractions.&amp;nbsp; The conference itself was excellent, and I really liked the amount of interaction that the crowd brought to each of the talks -- lots of great questions!&amp;nbsp; Special thanks to Tony Davis of &lt;a href="http://www.simple-talk.com/"&gt;Simple Talk&lt;/a&gt; for taking &lt;a href="http://sqljunkies.com/blogs/peter_debetta/default.aspx"&gt;Peter DeBetta&lt;/a&gt; and me out to a few pubs to sample some proper British ale.&lt;/p&gt;&lt;p&gt;And while I'm on the topic of the good, bad, and ugly of airlines, I'd like to thank Virgin Atlantic for being the best airline I've ever flown in terms of their customer service.&amp;nbsp; When you step up to the check in window and the first thing they tell you is, "sorry, but we oversold the flight...", your heart tends to sink.&amp;nbsp; But when they follow that up with, "...so do you mind if we upgrade you to first class?", they've suddenly made a customer for life. &amp;nbsp; Thanks, Virgin, for doing the right thing, instead of kicking me off the flight as I'm sure that almost any other airline would have done!&lt;br&gt;&lt;/p&gt;&lt;p&gt;Since you've read this far, I'll finish up with a link to something actually technical. Erland Sommarskog, King of the Comma-Delimited List, has finally released a SQL Server 2005 version of his famous &lt;a href="http://www.sommarskog.se/arrays-in-sql-2005.html"&gt;Arrays and Lists in SQL Server&lt;/a&gt; article. A fantastic read as always, and &lt;b&gt;highly&lt;/b&gt; recommended, as are all of Erland's articles.&lt;/p&gt;&lt;p&gt;Thanks for reading, and I hope to get back to some more regular--and technical--blogging soon!&amp;nbsp;&lt;/p&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=28746" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=28746</wfw:commentRss></entry><entry><title>Service Broker: Messages are queued, but how about readers?</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2007/01/10/26726.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:26726</id><created>2007-01-10T14:39:29Z</created><content type="text/html" mode="escaped">&lt;p&gt;The central database object that supports SQL Service Broker (SSB) is a queue. Messages sent between SSB services are queued and are delivered in order within a conversation. And that's exactly what one would expect from a queued solution.&lt;/p&gt;

&lt;p&gt;But how about other parts of the SSB equation? Do they also follow a queued/ordered path? Working on a solution recently, I decided to find out whether any guarantee existed with regard to readers getting messages in the order in which they had been waiting. I was curious as to what would happen if there were two or more readers waiting on a queue. Would the reader that had been waiting the longest be the first to pick up a message?&lt;/p&gt;

&lt;p&gt;To test this, I started with the following setup script to create a test database and a simple queue/service pair:&lt;/p&gt;

&lt;p&gt;&lt;span id="_ctl0_MainContent_PostFlatView"&gt;&lt;span&gt;
&lt;pre class="code"&gt;CREATE DATABASE SimpleSSB&lt;br&gt;GO&lt;br&gt;&lt;br&gt;USE SimpleSSB&lt;br&gt;GO&lt;br&gt;&lt;br&gt;--Create a database master key&lt;br&gt;CREATE MASTER KEY&lt;br&gt;ENCRYPTION BY PASSWORD = 'onteuhoeu'&lt;br&gt;GO&lt;br&gt;&lt;br&gt;--Create a message type&lt;br&gt;CREATE MESSAGE TYPE Simple_Msg&lt;br&gt;VALIDATION = EMPTY&lt;br&gt;GO&lt;br&gt;&lt;br&gt;--Create a contract based on the message type&lt;br&gt;CREATE CONTRACT Simple_Contract&lt;br&gt;(Simple_Msg SENT BY INITIATOR)&lt;br&gt;GO&lt;br&gt;&lt;br&gt;--Create a queue&lt;br&gt;CREATE QUEUE Simple_Queue&lt;br&gt;GO&lt;br&gt;&lt;br&gt;--Create a service &lt;br&gt;CREATE SERVICE Simple_Service&lt;br&gt;ON QUEUE Simple_Queue&lt;br&gt;(Simple_Contract)&lt;br&gt;GO&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt; Once this has been created, the test involved opening several SSMS windows (I used four) and starting readers waiting on the queue. Each window used the following code:&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;span id="_ctl0_MainContent_PostFlatView"&gt;&lt;span&gt;
&lt;pre class="code"&gt;USE SimpleSSB&lt;br&gt;GO&lt;br&gt;&lt;br&gt;WAITFOR&lt;br&gt;(&lt;br&gt;RECEIVE *&lt;br&gt;FROM Simple_Queue&lt;br&gt;), TIMEOUT 300000&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Finally, a test message was sent:&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;span id="_ctl0_MainContent_PostFlatView"&gt;&lt;span&gt;&lt;pre class="code"&gt;DECLARE @h UNIQUEIDENTIFIER&lt;br&gt;&lt;br&gt;BEGIN DIALOG CONVERSATION @h&lt;br&gt;FROM SERVICE Simple_Service&lt;br&gt;TO SERVICE 'Simple_Service'&lt;br&gt;ON CONTRACT Simple_Contract&lt;br&gt;WITH ENCRYPTION=OFF; &lt;br&gt;&lt;br&gt;SEND ON CONVERSATION @h &lt;br&gt;MESSAGE TYPE Simple_Msg&lt;br&gt;GO&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I expected the first reader window I'd opened to process this message as it had been waiting the longest and therefore should have been first in the queue. However, much to my surprise that's not what happened. Instead of the first reader receiving the message, the last reader--the one that had been waiting the least amount of time--got the message.&lt;/p&gt;&lt;p&gt;I puzzled over this for a while and finally decided to &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1091167&amp;amp;SiteID=1"&gt;ask the expert, Remus Rusanu&lt;/a&gt;, who spends time in the MSDN Service Broker forums answering questions. Remus explained that the behavior I saw in my test was actually done that way on purpose. The expected behavior for readers is not that of a queue, but rather that of a stack (i.e., LIFO rather than FIFO). &lt;/p&gt;&lt;p&gt;The reason for this, as it turns out, is for activation scenarios. Imagine that you have an activation procedure that uses a timeout of 40 seconds, and messages are coming in every 30 seconds. Only one activated procedure is needed to fill the load. But now imagine that a burst of activity occurs, and an additional instance of the procedure has been activated. Once normal activity resumed, if the system worked the way I expected it to one of the instances would pick up the first message then start waiting again. Then 30 seconds later the second instance would pick up the message (since it would have been waiting longer) and start waiting again. Back and forth, and the second--unnecessary--instance would never timeout. But the way the system is actually implemented, the first instance picks up the first message, then starts waiting again and picks up the second message as well--allowing the second instance to timeout since it's no longer needed.&lt;/p&gt;&lt;p&gt;This is not the behavior I either expected or was hoping for, but it makes perfect sense given what Service Broker is intended to do. I think it's a very interesting feature of the system.&lt;/p&gt;&lt;p&gt;My next post will show you how to work around this and get a queued behavior for readers. This is the behavior I required for the situation I was working on (you can read about it in my thread with Remus). Although probably not too common a requirement it is something I'm betting others will need from time to time.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=26726" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=26726</wfw:commentRss></entry><entry><title>Happy Holidays!</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2006/12/22/26322.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:26322</id><created>2006-12-22T16:31:15Z</created><content type="text/html" mode="escaped">I just want to wish everyone out there in the SQL Server community a happy, relaxing, and hopefully not at all productive holiday!&amp;nbsp; I'm betting things will be pretty quiet here at SQLBlog over the next several days, but make sure to say with us--there's a lot more content in store for 2007!&lt;br&gt;&lt;br&gt;In the meantime, make sure to check out the &lt;a href="http://www.simple-talk.com/opinion/opinion-pieces/the-simple-talk-cookbook/"&gt;Simple-Talk Cookbook&lt;/a&gt;, a collection of recipes from various members of the SQL Server community, including &lt;a href="http://sqljunkies.com/blogs/andrew_kelly/default.aspx"&gt;Andy Kelly&lt;/a&gt; and me. There are some interesting recipes in there, and I certainly hope mine are up to snuff!&lt;br&gt;&lt;br&gt;Again, have a great holiday season, and thank you all for a fantastic 2006!!&lt;br&gt;&lt;br&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=26322" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=26322</wfw:commentRss></entry><entry><title>Medians, ROW_NUMBERs, and performance</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2006/12/18/26199.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:26199</id><created>2006-12-18T18:30:27Z</created><content type="text/html" mode="escaped">A couple of days ago, Aaron Bertrand posted about &lt;a href="http://sqljunkies.com/blogs/aaron_bertrand/archive/2006/12/15/428.aspx"&gt;a method for calculating medians in SQL Server 2005&lt;/a&gt; using the ROW_NUMBER function in conjunction with the COUNT aggregate. This method (credited to Itzik Ben-Gan) is interesting, but I discovered an even better way to attack the problem in &lt;a href="http://www.amazon.com/Celkos-Analytics-Kaufmann-Management-Systems/dp/0123695120/sr=8-1/qid=1166482464/ref=sr_1_1/105-6595410-7450029?ie=UTF8&amp;amp;s=books"&gt;Joe Celko's Analytics and OLAP in SQL&lt;/a&gt;.&lt;br&gt;&lt;br&gt;Rather than using a COUNT aggregate in conjunction with the ROW_NUMBER function, Celko's method uses ROW_NUMBER twice: Once with an ascending sort, and again with a descending sort. The output rows can then be matched based on the ascending row number being within +/- 1 of the descending row number.&amp;nbsp; This becomes clearer with a couple of small examples:&lt;br&gt;&lt;br&gt;

&lt;table class="MsoTableGrid" cellpadding="0" cellspacing="0"&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;A&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;1&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;4&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;B&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;2&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;3&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;C&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;3&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;2&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;D&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;4&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;1&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;table class="MsoTableGrid" cellpadding="0" cellspacing="0"&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;A&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;1&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;5&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;B&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;2&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;4&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;C&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;3&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;3&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;D&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;4&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;2&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;E&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;5&lt;/p&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="MsoNormal"&gt;1&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;In the first table (even number of rows), the median rows are B and C. These can be matched based on [Ascending Column] IN ([Descending Column] + 1, [Descending Column] - 1). In the second table (odd number of rows), the median row is C, which is matched where [Ascending Column] = [Descending Column]. Note that in the second table, the match criteria &lt;/o:p&gt;for the first table does not apply -- so the generic expression to match either case is the combination of the two:&amp;nbsp; [Ascending Column] IN ([Descending Column], [Descending Column] + 1, [Descending Column] - 1).&lt;/p&gt;&lt;p class="MsoNormal"&gt;We can apply this logic within the AdventureWorks database to find the median of the "TotalDue" amount in the Sales.SalesOrderHeader table, for each customer:&lt;br&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;/p&gt;&lt;div class="code"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp; CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp; AVG(TotalDue)&lt;br&gt;FROM&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TotalDue,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ROW_NUMBER() OVER (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION BY CustomerId &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY TotalDue ASC, SalesOrderId ASC) AS RowAsc,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ROW_NUMBER() OVER (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION BY CustomerId &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY TotalDue DESC, SalesOrderId DESC) AS RowDesc&lt;br&gt;&amp;nbsp;&amp;nbsp; FROM Sales.SalesOrderHeader SOH&lt;br&gt;) x&lt;br&gt;WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp; RowAsc IN (RowDesc, RowDesc - 1, RowDesc + 1)&lt;br&gt;GROUP BY CustomerId&lt;br&gt;ORDER BY CustomerId;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;The equivalent logic using Itzik Ben-Gan's method follows:&lt;br&gt;&lt;/p&gt;&lt;div class="code"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp; CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp; AVG(TotalDue)&lt;br&gt;FROM&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TotalDue,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ROW_NUMBER() OVER (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION BY CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY TotalDue) AS RowNum,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT(*) OVER (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION BY CustomerId) AS RowCnt&lt;br&gt;&amp;nbsp;&amp;nbsp; FROM Sales.SalesOrderHeader&lt;br&gt;) x&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp; RowNum IN ((RowCnt + 1) / 2, (RowCnt + 2) / 2)&lt;br&gt;GROUP BY CustomerId&lt;br&gt;ORDER BY CustomerId;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Taking a look at the estimated execution plans for these two queries, we might believe that Ben-Gan's method is superior: Celko's algorithm requires an expensive intermediate sort operation and has an estimated cost of 4.96, compared to 3.96 for Ben-Gan's. &lt;br&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;Remember that these are merely estimates. And as it turns out, this is one of those times that the Query Optimizer's cost estimates are are totally out of line with the reality of what
happens when you actually run the queries. Although the performance
difference is not especially noticeable on a set of data as small as
that in Sales.SalesOrderHeader, check out the STATISTICS IO output. Celko's version does 703 logical reads; Ben-Gan's does an astonishing 140110!&lt;br&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;There is a good lesson to be learned from this: &lt;i&gt;Cost-based optimization is far from perfect!&lt;/i&gt; &lt;br&gt;Never completely trust what estimates tell you; they've come a long way, but clearly there is still some work to do in this area. The only way to actually determine that one query is better than another is to run it against a realistic set of data and look at how much IO and CPU time is actually used.&lt;br&gt;&lt;/p&gt;In this case, Ben-Gan's query probably should perform better than Celko's. It seems odd that the Query Processor can't collect the row counts at the same time it processes the row numbers. Regardless, as of today this is the best way to solve this problem... Not that I've ever needed a median in any production application I've worked on. But I suppose that's beside the point!&lt;br&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=26199" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=26199</wfw:commentRss></entry><entry><title>Log Buffer #21: A Carnival of the Vanities for DBAs</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2006/12/01/25783.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:25783</id><created>2006-11-30T12:28:40Z</created><content type="text/html" mode="escaped">&lt;p class="MsoNormal"&gt;Hello, there!&lt;span&gt;&amp;nbsp; &lt;/span&gt;You’ve
somehow managed to navigate your way through the blogosphere and into the 21st
edition of &lt;a href="http://www.pythian.com/blogs/about-log-buffer"&gt;Log Buffer&lt;/a&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;It’s fitting that this is the 21st edition, because that
just so happens to be the legal drinking age here in the United
  States. And the folks over at &lt;a href="http://www.oracle.com/index.html"&gt;Oracle&lt;/a&gt; sure need a drink or three
this week. &lt;a href="http://www.computerworld.com/"&gt;Computerworld’s&lt;/a&gt; Jaikumar
Vijayan reported on &lt;a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;articleId=9005383"&gt;a
study showing that Oracle has more security flaws than SQL Server&lt;/a&gt;. And over
at IT Toolbox, &lt;a href="http://blogs.ittoolbox.com/database/technology"&gt;Chris
Eaton&lt;/a&gt; was nice enough to &lt;a href="http://blogs.ittoolbox.com/database/technology/archives/oracle-gets-two-black-eyes-on-security-in-one-week-13099"&gt;link
us to the actual study&lt;/a&gt;, and in his post also mentioned that a security firm
called &lt;a href="http://www.argeniss.com/"&gt;Argeniss&lt;/a&gt; had promised to release
one Oracle security flaw every day this week. &lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;The &lt;a href="http://www.integrigy.com/oracle-security-blog"&gt;Oracle
Security Blog's&lt;/a&gt; &lt;a href="http://www.integrigy.com/oracle-security-blog/archive/2006/11/28/zero-day-week-suspended"&gt;update
on the topic&lt;/a&gt;, posted a few days after Chris's post, reveals that the week
of disclosure is not happening -- at least, not quite yet (Argeniss apparently
temporarily "suspended" the project).&lt;span&gt;&amp;nbsp;
&lt;/span&gt;But don’t worry!&lt;span&gt;&amp;nbsp; &lt;/span&gt;If you just
can’t live without that sticky-sweet feeling of bliss that accompanies finding
a particularly nasty hole in someone else's software, head on over to &lt;a href="http://awads.net/wp/"&gt;Eddie Awad's&lt;/a&gt; blog, where you can learn how to &lt;a href="http://awads.net/wp/2006/11/29/see-how-to-hack-oracle-using-dangling-cursor-snarfing/"&gt;snarf
a dangling cursor&lt;/a&gt;. And now I will sit back and watch as my inclusion of
that phrase gets this post banned by all of my readers' corporate indecency
filters. Snarf on!&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;For those &lt;strike&gt;serve up your customers' data to hackers on a
silver platter&lt;/strike&gt; live-on-the-edge types in the audience who have time to
worry about anything non-security-related amidst all of the concerns being
raised,&lt;span&gt;&amp;nbsp; &lt;/span&gt;there were a few interesting tidbits
posted this week. &lt;a href="http://www.dizwell.com/prod/blog/1"&gt;Edgar Hoover&lt;/a&gt;
dished up some &lt;a href="http://www.dizwell.com/prod/node/421"&gt;tips on using
functional indexes in 9i&lt;/a&gt;. And &lt;a href="http://technology.amis.nl/blog/"&gt;Lucas
Jellema&lt;/a&gt; showed us a way to &lt;a href="http://technology.amis.nl/blog/?p=1413"&gt;avoid
long strings of UNION ALL'd queries&lt;/a&gt; when trying to create "dummy" data. But
if you're running on Linux, good luck using these tips at all! &lt;a href="http://krow.livejournal.com/"&gt;Brian Aker&lt;/a&gt; clued us into the fact that &lt;a href="http://krow.livejournal.com/463145.html"&gt;most installations are
incredibly instable and that there just aren't enough experts around to fix the
problems&lt;/a&gt;. "Free" operating system. Expensive consultant needed to fix it.
What doesn't add up here?&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;For better or for worse, life in the &lt;a href="http://www.mysql.com/"&gt;MySQL&lt;/a&gt; camp was not nearly so exciting this
week. &lt;a href="http://blog.arabx.com.au/"&gt;Ronald&lt;/a&gt; wrote an interesting post
about &lt;a href="http://blog.arabx.com.au/?p=393"&gt;Pluggable Storage Engines&lt;/a&gt;,
but to me it sounds like it's just metadata management given a snazzy new name.
And over at the &lt;a href="http://marist89.blogspot.com/"&gt;So What Co-operative&lt;/a&gt;
blog, Jeff Hunter got some flack because he implied in a post that &lt;a href="http://marist89.blogspot.com/2006/11/where-am-i-deploying-mysql-revisited.html"&gt;MySQL
isn’t ready for prime time&lt;/a&gt; (i.e., no mission critical apps). For shame,
Jeff! Rounding things out was a good post by &lt;a href="http://feedblog.org/"&gt;Kevin
Burton&lt;/a&gt; all about &lt;a href="http://www.feedblog.org/2006/11/ethernet_latenc.html"&gt;Ethernet latency
and how it can affect database performance&lt;/a&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;It's life as usual for the &lt;a href="http://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt; and &lt;a href="http://www-306.ibm.com/software/data/db2/"&gt;DB2&lt;/a&gt; crowds. &lt;a href="http://blogs.ittoolbox.com/database/soup"&gt;Josh the PostgreSQL lead&lt;/a&gt;
posted not &lt;a href="http://blogs.ittoolbox.com/database/soup/archives/postgresql-application-performance-tips-part-1-13172"&gt;one&lt;/a&gt;,
but &lt;a href="http://blogs.ittoolbox.com/database/soup/archives/postgresql-application-performance-tips-part-2-13194"&gt;two&lt;/a&gt;
articles containing performance tips. And &lt;a href="http://blogs.ittoolbox.com/database/db2zos"&gt;Willie Favero&lt;/a&gt; pointed out
the availability of a couple of new IBM Red
Books: One covers the &lt;a href="http://blogs.ittoolbox.com/database/db2zos/archives/new-draft-redbook-available-powering-soa-with-ibm-data-servers-13170"&gt;oh-so-popular
topic of SOA&lt;/a&gt;, and the other is all about &lt;a href="http://blogs.ittoolbox.com/database/db2zos/archives/new-draft-redbook-available-lobs-with-db2-for-zos-stronger-and-faster-13169"&gt;LOB
data&lt;/a&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Which brings us nicely around to the world of &lt;a href="http://www.microsoft.com/sql/default.mspx"&gt;SQL Server&lt;/a&gt;. You didn’t
think I'd forgotten, did you? A good post came from &lt;a href="http://sqlservercode.blogspot.com/"&gt;Denis the SQL Menace&lt;/a&gt;, who brought
to light a not very well publicized feature of SQL Server 2005: the ability to
tell the engine to &lt;a href="http://sqlservercode.blogspot.com/2006/11/auto-update-statistics-asynchronously.html"&gt;update
statistics asynchronously&lt;/a&gt;. But this week's highlight came from &lt;a href="http://weblogs.sqlteam.com/mladenp/Default.aspx"&gt;Mladen Prajdic&lt;/a&gt;, who
discussed an interesting way to get &lt;a href="http://weblogs.sqlteam.com/mladenp/archive/2006/11/29/35688.aspx"&gt;high-precision
performance metrics in SQL Server, via a few SQLCLR routines&lt;/a&gt;. The only
problem with Mladen's technique is that it appears to only work on a single
thread at a time. Still, it's definitely an interesting technique to consider,
and a great SQLCLR sample to keep around.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;In the SQL Server tools department, we were informed by &lt;a href="http://simple-talk.com/community/blogs/bart/default.aspx"&gt;Bart Reed&lt;/a&gt;
of &lt;a href="http://www.red-gate.com/"&gt;Red Gate&lt;/a&gt; that &lt;a href="http://simple-talk.com/community/blogs/bart/archive/2006/11/24/8133.aspx"&gt;SQL
Prompt 3 might actually be coming some day&lt;/a&gt;! I was in the beta for this
product, and I have to say that it's looking pretty interesting -- I definitely
hope that some day is sooner rather than later, so get back to work and stop
blogging, Bart! Luckily, we don't have to wait for Red Gate to get some
enhancements to SQL Server Management Studio. &lt;a href="http://blogs.msdn.com/sqlrem/"&gt;Paul A. Mestemaker II&lt;/a&gt; provided &lt;a href="http://blogs.msdn.com/sqlrem/archive/2006/11/20/custom-reports-in-management-studio.aspx"&gt;detailed
information on how to add a custom report to Management Studio in SQL Server
2005 SP2&lt;/a&gt;. And low and behold, &lt;a href="http://sqlblogcasts.com/blogs/sqldbatips/default.aspx"&gt;Jasper Smith&lt;/a&gt;
has already published a very useful report, a &lt;a href="http://sqlblogcasts.com/blogs/sqldbatips/archive/2006/11/21/custom-ssms-reports-in-sp2-enterprise-manager-taskpad-view.aspx"&gt;recreation
of the much-missed Taskpad View from Enterprise Manager&lt;/a&gt;.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;Since not everything in our industry is product-dependent
(well, it's not supposed to be), let's not forget that database design
is a more or less transferable skill -- at least, if you have any clue about
what you're doing. The first consideration is usually data types, but as &lt;a href="http://tkyte.blogspot.com/"&gt;Tom Kyte&lt;/a&gt; pointed out, &lt;a href="http://tkyte.blogspot.com/2006/11/see-you-just-cannot-make-this-stuff-up.html"&gt;some
people just don't get the difference between strings and all of those other
newfangled types&lt;/a&gt; (as an aside: it was an Oracle person… should we be
surprised?)&lt;span&gt;&amp;nbsp; &lt;/span&gt;Apparently it was &lt;a href="http://www.db2portal.com/2006/11/character-versus-numeric-data-types.html"&gt;character
types vs. the world&lt;/a&gt; week in DB2 land as well, because &lt;a href="http://www.db2portal.com/blog.html"&gt;Craig Mullins&lt;/a&gt; also weighed in
with a post on the topic.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;To close, I'd like to point out that despite Eddie Awad's &lt;a href="http://awads.net/wp/2006/11/28/do-you-have-these-symptoms/"&gt;concerns
about laziness&lt;/a&gt;, I believe that all of the best computer professionals are
lazy at heart. That's why we use macros, create shortcuts, and script/automate
everything. We don't like working any more than we have to! And that is why
I'll leave it to not-so-lazy people -- like &lt;a href="http://www.celko.com/"&gt;Joe
Celko&lt;/a&gt; -- to come up with information on techniques such as an &lt;a href="http://joecelkothesqlapprentice.blogspot.com/2006/11/one-to-one-random-mapping-between-int.html"&gt;additive
congruenital method of generating values in pseudo-random order&lt;/a&gt;. Uh, yeah.&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;So with pseudo-randomness in mind, I bid you, kind reader,
adieu. And remember to watch out for those pesky dangling cursors! There's no worse feeling than coming in on a Monday morning and settling down with that first hot cup of coffee, only to discover that you've been snarfed over the weekend.  &lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;


&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=25783" width="1" height="1"&gt;</content><slash:comments>1</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=25783</wfw:commentRss></entry><entry><title>Slides and demos from AD-401: ADO.NET 2.0 Enhancements for SQL Server 2005</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2006/11/20/25589.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:25589</id><created>2006-11-20T14:14:54Z</created><content type="text/html" mode="escaped">I just got a request for my slides and demos from PASS, so I figured I would post a link to them here in case anyone else wants to check them out.&lt;br&gt;&lt;br&gt;The demos cover protected data sections, SqlConnectionStringBuilder, MARS, SqlBulkCopy, and SqlDependency.&amp;nbsp; Just for the record: I make no guarantees about the quality, usefulness, or lack of bugs in the code -- use at your own risk.&amp;nbsp; I probably don't really need to say that, but I've seen some strange things lately and I'm getting paranoid!&lt;br&gt;&lt;br&gt;Anyway, you can &lt;a href="http://www.datamanipulation.net/Machanic_AD401_Slides_and_Demos.zip"&gt;download here.&lt;/a&gt;&amp;nbsp; Enjoy, and as always feel free to leave me a comment if you have any questions, feedback, or anything else.&lt;br&gt;&lt;br&gt;&lt;br&gt; 
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=25589" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=25589</wfw:commentRss></entry><entry><title>PASS 2006 and the joys of flight</title><link rel="alternate" type="text/html" href="http://www.sqljunkies.com/WebLog/amachanic/archive/2006/11/18/25564.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:25564</id><created>2006-11-18T15:28:16Z</created><content type="text/html" mode="escaped">As you're probably aware if you subscribe to any SQL Server-related content, this week Seattle was host to the 2006 Professional Association of SQL Server conference. I had a great time at the conference this year, and really got a lot of value out of the experience. Good job, PASS!&lt;br&gt;&lt;br&gt;While I was there, I did a couple of short talks at the &lt;a href="http://www.simple-talk.com/"&gt;Simple Talk&lt;/a&gt; booth, did a session for the conference on ADO.NET 2.0, and spent most of the rest of the time networking and discussing my favorite topic (SQL Server, of course) with the best minds in the industry. One of the greatest features of this year's conference was the "Microsoft Interaction Lounge," an area at the back of the main hall where various SQL Server team members were stationed at tables, ready to answer questions from attendees.&amp;nbsp; I spent a large amount of time in that area and was able to get some wonderful insights into the product.&amp;nbsp; Unfortunately, I was often the only non-Microsoft attendee in sight, so I think the area was a bit under-utilized.&amp;nbsp; Too bad for other attendees, but great news for me -- and my sincere thanks to those Microsoft employees who were patient enough to let me bend their ears for the hours I spent there!&lt;br&gt;&lt;br&gt;Alas, the week was marred on either end by air travel, to and from Boston from Seattle. A couple of weeks ago my Alaska Airlines flights (booked three months in advance) were canceled by the airline, and their absolutely deplorable, obviously misnamed, "customer service" department refused to help in any way when I asked them to get me on another set of flights. I managed to book Delta to Seattle, and was shocked to discover upon arriving at the airport that the flight was a code share with... who else but Alaska Airlines!&amp;nbsp; Typical very poor coach flight: zero leg room to begin with, made worse when the person in front of me moved her chair all the way back as soon as we left the ground, and the guy next to me -- probably 150 pounds overweight -- literally spilled over onto my lap.&lt;br&gt;&lt;br&gt;Coming back I was lucky enough to book the flight with &lt;a href="http://www.jetblue.com/"&gt;jetBlue&lt;/a&gt;. This was my first time flying that airline, and I knew something was a bit different when I got on and noticed both the lack of first class seating, and was greeted by a jetBlue employee with a big smile instead of the usual "who cares" attitude I get from the airlines. I also knew that I had made the right choice when I noticed that Tony Mann from &lt;a href="http://www.mannpublishing.com/rational/"&gt;Rational Press&lt;/a&gt; was on the flight! Leather seats, probably twice the leg room I had on the flight out, and a TV for every seat, translated into a pretty great flight (well, as far as flights go, at least). Plus the snacks were better, and the airline hands out free samples of various products (such as an eye mask and lip balm). Such a better experience than what I'm used to; I will definitely prefer jetBlue going forward.&lt;br&gt;&lt;br&gt;So all in all, a pretty great week, ending on a better note than on which it began.&amp;nbsp; And I have plenty of blog fodder in mind.&amp;nbsp; So watch this space as I decompress and get back into technical mode!&lt;br&gt; 
&lt;br&gt;&lt;hr&gt;&lt;br&gt;Cross-posted from SQLBlog! - &lt;a href="http://www.sqlblog.com"&gt;http://www.sqlblog.com&lt;/a&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&lt;img src="http://www.sqljunkies.com/WebLog/aggbug.aspx?PostID=25564" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://www.sqljunkies.com/WebLog/amachanic/commentrss.aspx?PostID=25564</wfw:commentRss></entry></feed>