Film director Stanley Kubrick would make a film in a specific genre, after which there was almost no point in making movies in that genre any more. War movie - Paths of Glory, political satire - Dr Strangelove , historical film - Spartacus, science fiction - 2001 A Space Odyssey, horror - The Shining. Itzik Ben-Gan managed to do with his book what Kubrick did with his films. There just is no point in writing another book on T-SQL after his.
The first thing I looked for when I picked the book at the post office was the section on Outer Joins. A common question when using outer joins that is the source of lot of confusion is whether to specify a predicate in the ON or WHERE clause of the query. Itzik explains it definitively: " You can see that with respect to rows from the preserved side of an outer join, the filter based on the ON predicate is not final. In other words, the ON predicate does not detremine whether the row will show up in the output, only whether it will be matched with rows from the other side. So when you need to express a predicate that is not final - meaning a predicate that determines which rows to match from the nonpreserved side - specify the predicate in the ON clause. When you need a filter to be applied after outer rows are produced, and you want the filter to be final, specify the predicate in the WHERE clause. "
If only I this book existed ten years ago I would have avoided some of the mistakes I made through the years, only because some fundamental things were never clearly explained. Itzik fills the gaps for an exprienced DBA and gives a perfect basis for a novice. The fundamentals become crystal clear so that building on top of it is easy. Perhaps this can be best illustrated by the following example:
"Can you figure out how to write an UPDATE statement that swaps the values in col1 and col2? In most programming languages where expressions and assigments are evaluated in some order (typically left to write) , you need a temporary variable. However, because in SQL all assignments take place as if at the same point in time, the solution is very simple:
set col1= col2, col2 = col1;
In both assigments the source column values used are those prior to the update, so you don't need a temporary variable."
Now why did no other book I read ever give this simple example?
Common Table Expressions are explained really well, especially updating and deleting data using CTEs. Actually, the book covers all the 2005 and 2008 related enhacements ROW_NUMBER, RANK, DENSE_RANK and NTILE, Recursive Queries, APPLY,CROSS APPLY, OUTER APPLY,EXCEPT and INTERSECT, TRY...CATCH, TOP Enhancements, PIVOT UNPIVOT, DDL Triggers, MERGE. But it covers it in such a way that nothing seems complicated. We should give it to all out C++ programmers as well.
It was a pleasure reading the book