This book and its sequelInside Microsoft SQL Server 2005: T-SQL Programmingcover advanced TSQL querying, query tuning, and programming in SQL Server 2005. They are designed for programmers and DBAs who need to write and optimize code in both SQL Server 2000 and 2005. For brevity, I'll refer to the books as Inside T-SQL Querying and Inside T-SQL Programming.
The books focus on practical common problems, discussing several approaches to tackle each one. You will be introduced to many polished techniques that will enhance your toolbox and coding vocabulary, allowing you to provide efficient solutions in a natural manner.
The books unveil the power of set-based querying, and explain why it's usually superior to procedural programming with cursors and the like. At the same time, the books teach you how to identify the few scenarios where cursor-based solutions are superior to set-based ones.
The books also cover other much debated constructssuch as temporary tables, dynamic execution, XML and .NET integrationwhich hold great power, but at the same time great risk. These constructs require programmatic maturity. These books will teach you how to use them wisely, in efficient and safe ways where they are relevant.
The first bookInside T-SQL Queryingfocuses on set-based querying, and I recommend that you read it first. The second bookInside T-SQL Programmingfocuses on procedural programming and assumes you read the first book or have sufficient querying background.
Inside T-SQL Querying starts with three chapters that lay the foundation of logical and physical query processing required to gain the most from the rest of the chapters.
The first chapter covers logical query processing. It describes in detail the logical phases involved in processing queries, the unique aspects of SQL querying, and the special mindset you need in order to program in a relational, set-oriented environment.
The second chapter covers physical query processing. It describes in detail the way the SQL Server engine processes queries, and compares and contrasts physical query processing with logical query processing. This chapter was written by Lubor Kollar. Lubor was a group program manager during the SQL Server 2005 development, and his team was responsible for the "bottom" part of the Relational Enginefrom query compilation and optimization to query execution, transactional consistency, backup/restore, and high availability. Table and Index Partitioning, Database Mirroring, Database Snapshot, Snapshot Isolation, Recursive Queries and other T-SQL query improvements, Database Tuning Advisor, and Online Index creation and maintenance were the major SQL Server 2005 features his team was working on. Few people in the world probably know the subject of query optimization as well as Lubor does. I find it a privilege to have one of the designers of the optimizer explain it in his own words.