New book: Inside Microsoft SQL Server 2008: T-SQL Querying

While writing this post about the new Inside Microsoft SQL Server 2008: T-SQL Querying by Itzik Ben-Gan, I emailed the author for a little assistance. Itzik is not only a T-SQL expert, master teacher, and bestselling author, he’s also a wonderful person and friend. Most of the time, he’s traveling the world with his wife Lilach, teaching and consulting. So whenever he’s in the Pacific NW, we try to get together for good conversation, food, and drink, particularly a pint of Guinness or two.

I asked Itzik if he would say a few words about the differences between his new book and his previous SQL Server 2005 edition. He pointed me to a blog post of his that has all that and more. With Itzik’s kindly permission, I’ve copied the post below from its SQL Server Magazine online home. And, as a special bonus, we’ve included one of the very popular logic puzzles from the book (we’ll post the answer to the puzzle next week).

Many thanks, Itzik! I owe you a Guinness.

From Itzik Ben-Gan’s Blog:

A few weeks ago the book Inside Microsoft SQL Server 2008: T-SQL Querying was sent to the printers, and it should be available in the next few days in the book stores. Like with your kids, I guess you’re not suppose to point out a favorite, but I can’t resist… I’ve been involved (and still am) in writing several books about SQL Server 2008, and T-SQL Querying is by far my favorite—it’s closest to my heart. When planning the book I was thinking about the book that I always wanted to read. I love SQL, and I feel that in order to appreciate the true depths of the language, you should familiarize yourself with the mathematical roots of the relational model, the model itself, and algorithmic complexity. Then you can start delving into the various aspects of querying and query tuning, and attain immense satisfaction and great insights while doing so.

The book was written by a group of authors which I’m honored and proud to be part of. Steve Kass wrote two chapters: one about set theory and predicate logic, and another about algorithms and complexity. Dejan Sarka wrote a chapter about the relational model. Lubor Kollar wrote a chapter about querying partition tables. I wrote the other eight chapters focusing on querying and query tuning, and an appendix about logic puzzles. Steve Kass was the main Technical Editor of the book, and Umachandar Jayachandran (UC) helped by editing a couple of chapters. César Galindo-Legaria wrote the foreword.

For those that have some of my other books and wonder what’s the difference…

If you read the book Microsoft SQL Server 2008: T-SQL Fundamentals, it was designed for any audience that needs to write T-SQL code, including people who just started using T-SQL. It focuses on logical aspects of T-SQL and on the fundamentals. The T-SQL Querying book is much more advanced, and actually assumes as prerequisites that you read T-SQL Fundamentals or have equivalent knowledge. T-SQL Querying delves into the fundamentals much more intensely, and then covers advanced aspects of querying and query tuning, focusing on both logical and physical processing.

If you read Inside Microsoft SQL Server 2005: T-SQL Querying, you will find plenty of new stuff in the new 2008 edition. There are four completely new chapters, and the existing chapters were updated to incorporate new features in SQL Server 2008, and new insights about existing subjects. Also, the appendix with the logic puzzles was rewritten with a new set of puzzles.

BTW, we made a poster available for download containing a diagram of Logical Query Processing from the first chapter. To me, this diagram captures the essence of SQL. You can download the poster from the book’s companion website, or from the following direct link.

A Logic Puzzle: Catching a Train

(from Inside Microsoft SQL Server 2008: T-SQL Querying)

Two trains race toward each other on a railway segment that’s 100 miles long. The trains are traveling at 100 mph. A mosquito flying at 200 mph flies from one train toward the other, and as soon as it arrives at the other train, it flips its direction and flies back toward the first train. The mosquito continues bouncing back and forth between the trains until the trains crash. What’s the total distance that the mosquito covers until the moment of the crash?

As for the logic puzzle, I think it’s a bit of a trick question. If the trains start out 100 miles apart, and they each travel at 100mph, it will take them 30 minutes to travel 50 miles, then they’ll crash. If the mosquito is flying back and forth continuously for that 30 minutes, at 200mph, it will travel 100 miles. We don’t need to know the exact positions of the trains each time it "bounces".