Book description
Tackle the toughest set-based querying and query tuning
problems—guided by an author team with in-depth, inside
knowledge of T-SQL. Deepen your understanding of architecture and
internals—and gain practical approaches and advanced
techniques to optimize your code’s performance.
Discover how to:
Move from procedural programming to the language of sets and logic
Optimize query tuning with a top-down methodology
Assess algorithmic complexity to predict performance
Compare data-aggregation techniques, including new grouping sets
Manage data modification—insert, delete, update, merge—for performance
Write more efficient queries against partitioned tables
Work with graphs, trees, hierarchies, and recursive queries
Plus—Use pure-logic puzzles to sharpen your problem-solving skills
Table of contents
- Inside Microsoft® SQL Server® 2008: T-SQL Querying
- Foreword
- Acknowledgments
- Introduction
-
1. Logical Query Processing
- Logical Query Processing Phases
- Sample Query Based on Customers/Orders Scenario
- Logical Query Processing Phase Details
- Further Aspects of Logical Query Processing
- Conclusion
-
2. Set Theory and Predicate Logic
- An Example of English-to-Mathematics Translation
- Set Theory
- Predicate Logic
- Relations
- A Practical Application
- Conclusion
- 3. The Relational Model
-
4. Query Tuning
- Sample Data for This Chapter
- Tuning Methodology
- Tools for Query Tuning
-
Index Tuning
- Table and Index Structures
-
Index Access Methods
- Table Scan/Unordered Clustered Index Scan
- Unordered Covering Nonclustered Index Scan
- Ordered Clustered Index Scan
- Ordered Covering Nonclustered Index Scan
- The Storage Engine’s Treatment of Scans
- Nonclustered Index Seek + Ordered Partial Scan + Lookups
- Unordered Nonclustered Index Scan + Lookups
- Clustered Index Seek + Ordered Partial Scan
- Covering Nonclustered Index Seek + Ordered Partial Scan
- Index Intersection
- Filtered Indexes and Statistics
- Indexed Views
-
Analysis of Indexing Strategies
- Table Scan (Unordered Clustered Index Scan)
- Unordered Covering Nonclustered Index Scan
- Unordered Nonclustered Index Scan + Lookups
- Nonclustered Index Seek + Ordered Partial Scan + Lookups
- Clustered Index Seek + Ordered Partial Scan
- Covering Nonclustered Index Seek + Ordered Partial Scan
- Summary of Analysis of Indexing Strategy
- Fragmentation
- Partitioning
- Preparing Sample Data
- An Examination of Set-Based vs. Iterative/Procedural Approaches and a Tuning Exercise
- Conclusion
-
5. Algorithms and Complexity
- Do You Have a Quarter?
- How Algorithms Scale
- Classic Algorithms and Algorithmic Strategies
- A Practical Application
- Conclusion
-
6. Subqueries, Table Expressions, and Ranking Functions
- Subqueries
- Table Expressions
- Analytical Ranking Functions
- Auxiliary Table of Numbers
- Missing and Existing Ranges (Also Known as Gaps and Islands)
- Conclusion
- 7. Joins and Set Operations
- 8. Aggregating and Pivoting Data
- 9. TOP and APPLY
-
10. Data Modification
-
Inserting Data
- Enhanced VALUES Clause
- SELECT INTO
- BULK Rowset Provider
-
Minimally Logged Operations
- Analyzing Logging Behavior
-
Testing Insert Scenarios
- Scenario 1: SELECT INTO, FULL Recovery
- Scenario 2: SELECT INTO, Non-FULL Recovery
- Scenario 3: INSERT SELECT, Empty Heap, TABLOCK
- Scenario 4: INSERT SELECT, Nonempty Heap, TABLOCK
- Scenario 5: INSERT SELECT, Empty Heap, Without TABLOCK
- Scenario 6: INSERT SELECT, Empty B-Tree, TABLOCK
- Scenario 7: INSERT SELECT, Nonempty B-Tree, TABLOCK, TF-610 Off, New Key Range
- Scenario 8: INSERT SELECT, Nonempty B-Tree, TABLOCK, TF-610 On, New Key Range
- Scenario 9: INSERT SELECT, Nonempty B-Tree, TABLOCK, Merged Key Range
- Scenario 10: INSERT SELECT, Empty B-Tree, Without TABLOCK, TF-610 Off
- Scenario 11: INSERT SELECT, Empty B-Tree, Without TABLOCK, TF-610 On
- Scenario 12: INSERT SELECT, Nonempty B-Tree, without TABLOCK, TF-610 Off, New Key Range
- Scenario 13: INSERT SELECT, Nonempty B-Tree, without TABLOCK, TF-610 On, New Key Range
- Scenario 14: INSERT SELECT, Nonempty B-Tree, without TABLOCK, Merged Key Range
- Summary of Minimal Logging
- INSERT EXEC
- Sequence Mechanisms
- GUIDs
- Deleting Data
- Updating Data
- Merging Data
- OUTPUT Clause
- Conclusion
-
Inserting Data
- 11. Querying Partitioned Tables
- 12. Graphs, Trees, Hierarchies, and Recursive Queries
-
A. Logic Puzzles
-
Puzzles
- Puzzle 1: Remainders
- Puzzle 2: Round Manhole Covers
- Puzzle 3: Shaking Hands
- Puzzle 4: Then There Were Five?
- Puzzle 5: Arranging Soldiers in a Row
- Puzzle 6: Crossing the Tunnel
- Puzzle 7: Escaping a Cave
- Puzzle 8: Free Tuna
- Puzzle 9: Naming an Heir
- Puzzle 10: The Next Element in a Series
- Puzzle 11: Same Birthday
- Puzzle 12: Catching a Train
- Puzzle 13: Prisoners and Switches
- Puzzle 14: Probabilities in China
- Puzzle 15: Two Mathematicians
- Puzzle 16: Crazy Sequence
- Puzzle 17: Minimum Number of Weights
- Puzzle 18: Counting Triangles
- Puzzle 19: Counterfeit Coins
- Puzzle 20: Too Clever by Half
- Puzzle 21: A Cat, a String, and the Earth
- Puzzle 22: Josephus Problem
- Puzzle 23: Shipping Algebra
- Puzzle 24: Equilateral Triangles Puzzle
-
Puzzle Solutions
- Puzzle 1: Remainders
- Puzzle 2: Round Manhole Covers
- Puzzle 3: Shaking Hands
- Puzzle 4: Then There Were Five?
- Puzzle 5: Arranging Soldiers in a Row
- Puzzle 6: Crossing the Tunnel
- Puzzle 7: Escaping a Cave
- Puzzle 8: Free Tuna
- Puzzle 9: Naming an Heir
- Puzzle 10: The Next Element in a Series
- Puzzle 11: Same Birthday
- Puzzle 12: Catching a Train
- Puzzle 13: Prisoners and Switches
- Puzzle 14: Probabilities in China
- Puzzle 15: Two Mathematicians
- Puzzle 16: Crazy Sequence
- Puzzle 17: Minimum Number of Weights
- Puzzle 18: Counting Triangles
- Puzzle 19: Counterfeit Coins
- Puzzle 20: Too Clever by Half
- Puzzle 21: A Cat, a String, and the Earth
- Puzzle 22: Josephus Problem
- Puzzle 23: Shipping Algebra
- Puzzle 24: Equilateral Triangles Puzzle
- Conclusion
-
Puzzles
- B. About the Authors
- Index
- About the Authors
- Copyright
Product information
- Title: Inside Microsoft® SQL Server® 2008: T-SQL Querying
- Author(s):
- Release date: March 2009
- Publisher(s): Microsoft Press
- ISBN: 9780735634763
You might also like
book
Expert Scripting and Automation for SQL Server DBAs
Automate your workload and manage more databases and instances with greater ease and efficiency by combining …
book
Learning SQL, 3rd Edition
As data floods into your company, you need to put it to work right away—and SQL …
book
Pro SQL Server 2019 Administration: A Guide for the Modern DBA
Use this comprehensive guide for the SQL Server DBA, covering all that practicing database administrators need …
book
Healthy SQL : A Comprehensive Guide to Healthy SQL Server Performance
Healthy SQL is about ensuring the ongoing performance health of a SQL Server database. An unhealthy …