Code snippets for Chapters 1, 2, 3, 4, 5, 7, 9 and 10 are available here.
The partitioning scripts, and sample data, referred to in Chapter 7 can be downloaded here.
[Link is not working yet.]
Chapter 6 (Indexes) code and sample databases can be downloaded from Kimberly Tripp’s blog at:
Chapter 3: Query Execution
from Inside SQL Server 2005 – Query Tuning and Optimization
This document is no longer available for separate download. The chapter has been updated and included in the SQL Server 2012 Internals book.
You can download scripts for AdventureWorks2008 databases from the Microsoft CodePlex site here.
Other databases mentioned in the book (Northwind, Northwind2, pubs) can be built from these scripts here.