Skip to:Content
|
Bottom
Cover image for Inside Microsoft SQL server 2005 : T-SQL querying
Title:
Inside Microsoft SQL server 2005 : T-SQL querying
Personal Author:
Publication Information:
Redmond, WA : Microsoft Press, 2006
ISBN:
9780735623132

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010159125 QA76.73.S67 B46 2006 Open Access Book Book
Searching...

On Order

Summary

Summary

Inside Microsoft SQL Server 2005: t-SQL Querying deals with computers/software.


Author Notes

Dejan Sarka is a mentor with SolidQ and focuses on development of database and business intelligence applications. He is a frequent speaker at international conferences such as TechEd, SqlDevCon, and PASS. He is the founder of the Slovenian SQL Server and .NET Users Group. As main author or coauthor, Dejan has written nine books about SQL Server. He has also developed three courses for SolidQ: Data Modeling Essentials, Data Quality and Master Data Management, and Data Mining.


Table of Contents

Forewordp. xiii
Prefacep. xv
Acknowledgmentsp. xix
Introductionp. xxiii
Organization of This Bookp. xxiii
System Requirementsp. xxiii
Installing Sample Databasesp. xxiv
Updatesp. xxiv
Code Samplesp. xxiv
Support for This Bookp. xxiv
1 Logical Query Processingp. 1
Logical Query Processing Phasesp. 3
Brief Description of Logical Query Processing Phasesp. 4
Sample Query Based on Customers/Orders Scenariop. 4
Logical Query Processing Phase Detailsp. 6
Step 1 Performing a Cartesian Product (Cross Join)p. 6
Step 2 Applying the ON Filter (Join Condition)p. 8
Step 3 Adding Outer Rowsp. 10
Step 4 Applying the WHERE Filterp. 11
Step 5 Groupingp. 12
Step 6 Applying the CUBE or ROLLUP Optionp. 13
Step 7 Applying the HAVING Filterp. 13
Step 8 Processing the SELECT Listp. 14
Step 9 Applying the DISTINCT Clausep. 15
Step 10 Applying the ORDER BY Clausep. 15
Step 11 Applying the TOP Optionp. 18
New Logical Processing Phases in SQL Server 2005p. 19
Table Operatorsp. 19
OVER Clausep. 27
Set Operationsp. 29
Conclusionp. 30
2 Physical Query Processingp. 31
Flow of Data During Query Processingp. 32
Compilationp. 35
Algebrizerp. 37
Optimizationp. 40
Working with the Query Planp. 47
Update Plansp. 59
Conclusionp. 63
Acknowledgmentp. 63
3 Query Tuningp. 65
Sample Data for This Chapterp. 66
Tuning Methodologyp. 69
Analyze Waits at the Instance Levelp. 71
Correlate Waits with Queuesp. 80
Determine Course of Actionp. 81
Drill Down to the Database/File Levelp. 82
Drill Down to the Process Levelp. 84
Tune Indexes/Queriesp. 103
Tools for Query Tuningp. 105
syscacheobjectsp. 105
Clearing the Cachep. 105
Dynamic Management Objectsp. 106
STATISTICS IOp. 106
Measuring the Run Time of Queriesp. 106
Analyzing Execution Plansp. 107
Hintsp. 119
Traces/Profilerp. 121
Database Engine Tuning Advisorp. 121
Index Tuningp. 122
Table and Index Structuresp. 122
Index Access Methodsp. 132
Index Optimization Scalep. 155
Fragmentationp. 168
Partitioningp. 170
Preparing Sample Datap. 170
Data Preparationp. 170
TABLESAMPLEp. 177
An Examination of Set-Based vs. Iterative/Procedural Approaches, and a Tuning Exercisep. 180
Additional Resourcesp. 187
Conclusionp. 189
4 Subqueries, Table Expressions, and Ranking Functionsp. 191
Subqueriesp. 191
Self-Contained Subqueriesp. 192
Correlated Subqueriesp. 195
Misbehaving Subqueriesp. 208
Uncommon Predicatesp. 209
Table Expressionsp. 211
Derived Tablesp. 211
Common Table Expressions (CTE)p. 214
Analytical Ranking Functionsp. 222
Row Numberp. 224
Rank and Dense Rankp. 246
NTILEp. 247
Auxiliary Table of Numbersp. 252
Existing and Missing Ranges (Also Known as Islands and Gaps)p. 256
Missing Ranges (Also Known as Gaps)p. 257
Existing Ranges (Also Known as Islands)p. 260
Conclusionp. 262
4 Joins and Set Operationsp. 263
Joinsp. 263
Old Style vs. New Stylep. 263
Fundamental Join Typesp. 264
Further Examples of Joinsp. 276
Sliding Total of Previous Yearp. 287
Join Algorithmsp. 291
Separating Elementsp. 296
Set Operationsp. 303
UNIONp. 304
EXCEPTp. 305
INTERSECTp. 307
Precedence of Set Operationsp. 309
Using INTO with Set Operationsp. 310
Circumventing Unsupported Logical Phasesp. 310
Conclusionp. 313
6 Aggregating and Pivoting Datap. 315
OVER Clausep. 315
Tiebreakersp. 319
Running Aggregationsp. 321
Cumulative Aggregationsp. 323
Sliding Aggregationsp. 328
Year-To-Date (YTD)p. 330
Pivotingp. 331
Pivoting Attributesp. 331
Relational Divisionp. 335
Aggregating Datap. 337
Unpivotingp. 341
Custom Aggregationsp. 344
Custom Aggregations Using Pivotingp. 345
User Defined Aggregates (UDA)p. 347
Specialized Solutionsp. 358
Histogramsp. 367
Grouping Factorp. 371
CUBE and ROLLUPp. 374
CUBEp. 374
Rollupp. 379
Conclusionp. 380
7 TOP and APPLYp. 381
SELECT TOPp. 381
TOP and Determinismp. 383
TOP and Input Expressionsp. 385
TOP and Modificationsp. 385
APPLYp. 388
Solutions to Common Problems Using TOP and APPLYp. 391
TOP n for Each Groupp. 391
Matching Current and Previous Occurrencesp. 397
Pagingp. 402
Random Rowsp. 411
Medianp. 413
Conclusionp. 415
8 Data Modificationp. 417
Inserting Datap. 417
SELECT INTOp. 417
INSERT EXECp. 419
Inserting New Rowsp. 423
INSERT with OUTPUTp. 426
Sequence Mechanismsp. 428
Deleting Datap. 435
TRUNCATE vs. DELETEp. 435
Removing Rows with Duplicate Datap. 435
DELETE Using Joinsp. 438
DELETE with OUTPUTp. 441
Updating Datap. 443
UPDATE Using Joinsp. 443
UPDATE with OUTPUTp. 447
SELECT and UPDATE Statement Assignmentsp. 450
Other Performance Considerationsp. 454
Conclusionp. 457
9 Graphs, Trees, Hierarchies, and Recursive Queriesp. 459
Terminologyp. 460
Graphsp. 460
Treesp. 461
Hierarchiesp. 461
Scenariosp. 462
Employee Organizational Chartp. 462
Bill of Materials (BOM)p. 464
Road Systemp. 468
Iteration/Recursionp. 471
Subordinatesp. 472
Ancestorsp. 484
Subgraph/Subtree with Path Enumerationp. 487
Sortingp. 491
Cyclesp. 502
Materialized Pathp. 505
Maintaining Datap. 506
Queryingp. 512
Nested Setsp. 517
Assigning Left and Right Valuesp. 518
Queryingp. 527
Transitive Closurep. 530
Directed Acyclic Graphp. 531
Conclusionp. 548
A Logic Puzzlesp. 551
Puzzlesp. 551
Puzzle 1 Medication Tabletsp. 551
Puzzle 2 Chocolate Barp. 552
Puzzle 3 To a Tp. 552
Puzzle 4 On the Dotp. 553
Puzzle 5 Rectangles in a Squarep. 553
Puzzle 6 Measuring Time by Burning Ropesp. 553
Puzzle 7 Arithmetic Maximum Calculationp. 554
Puzzle 8 Covering a Chessboard with Domino Tilesp. 554
Puzzle 9 The Missing Buckp. 555
Puzzle 10 Flipping Lamp Switchesp. 555
Puzzle 11 Cutting a Stick to Make a Trianglep. 555
Puzzle 12 Rectangle Within a Circlep. 555
Puzzle 13 Monty Hall Problemp. 556
Puzzle 14 Piece of Cakep. 556
Puzzle 15 Cards Facing Upp. 556
Puzzle 16 Basic Arithmeticp. 557
Puzzle 17 Self-Replicating Code (Quine)p. 557
Puzzle 18 Hiking a Mountainp. 557
Puzzle 19 Find the Pattern in the Sequencep. 558
Puzzle Solutionsp. 558
Puzzle 1 Medication Tabletsp. 558
Puzzle 2 Chocolate Barp. 558
Puzzle 3 To a Tp. 558
Puzzle 4 On the Dotp. 559
Puzzle 5 Rectangles in a Squarep. 559
Puzzle 6 Measuring Time by Burning Ropesp. 561
Puzzle 7 Arithmetic Maximum Calculationp. 561
Puzzle 8 Covering a Chessboard with Domino Tilesp. 561
Puzzle 9 The Missing Buckp. 562
Puzzle 10 Alternating Lamp Statesp. 562
Puzzle 11 Cutting a Stick to Make a Trianglep. 562
Puzzle 12 Rectangle Within a Circlep. 563
Puzzle 13 Monty Hall Problemp. 563
Puzzle 14 Piece of Cakep. 565
Puzzle 15 Cards Facing Upp. 565
Puzzle 16 Basic Arithmeticp. 565
Puzzle 17 Self-Replicating Code (Quine)p. 566
Puzzle 18 Hiking a Mountainp. 566
Puzzle 19 Find the Pattern in the Sequencep. 567
Conclusionp. 567
Go to:Top of Page