| Foreword |
|
xxi | |
| Prefaces |
|
xxiii | |
| System Requirements |
|
xxxv | |
| Part I Overview |
|
|
The Evolution of Microsoft SQL Server: 1989 to 2000 |
|
|
3 | (28) |
|
SQL Server: The Early Years |
|
|
4 | (2) |
|
|
|
6 | (1) |
|
|
|
7 | (1) |
|
Microsoft SQL Server Ships |
|
|
8 | (2) |
|
|
|
10 | (1) |
|
|
|
11 | (2) |
|
|
|
13 | (2) |
|
|
|
14 | (1) |
|
|
|
14 | (1) |
|
SQL Server for Windows NT |
|
|
15 | (5) |
|
Success Brings Fundamental Change |
|
|
20 | (1) |
|
The End of Joint Development |
|
|
21 | (2) |
|
|
|
23 | (2) |
|
|
|
25 | (1) |
|
|
|
26 | (2) |
|
Software for the New Century |
|
|
28 | (3) |
|
|
|
31 | (38) |
|
|
|
33 | (4) |
|
|
|
33 | (4) |
|
DBMS-Enforced Data Integrity |
|
|
37 | (5) |
|
Declarative Data Integrity |
|
|
38 | (1) |
|
|
|
39 | (1) |
|
Check Constraints and Rules |
|
|
40 | (1) |
|
|
|
40 | (1) |
|
|
|
40 | (2) |
|
|
|
42 | (2) |
|
|
|
42 | (1) |
|
|
|
43 | (1) |
|
|
|
43 | (1) |
|
|
|
43 | (1) |
|
Symmetric Server Architecture |
|
|
44 | (2) |
|
Traditional Process/Thread Model |
|
|
44 | (1) |
|
SQL Server Process/Thread Model |
|
|
45 | (1) |
|
|
|
45 | (1) |
|
|
|
46 | (1) |
|
Monitoring and Managing Security |
|
|
47 | (1) |
|
|
|
47 | (1) |
|
Distributed Data Processing |
|
|
48 | (2) |
|
|
|
50 | (2) |
|
|
|
52 | (5) |
|
SQL Server Enterprise Manager |
|
|
52 | (2) |
|
Distributed Management Objects |
|
|
54 | (1) |
|
Windows Management Instrumentation |
|
|
54 | (1) |
|
SQL-DMO and Visual Basic Scripting |
|
|
55 | (1) |
|
|
|
55 | (2) |
|
SQL Server Utilities and Extensions |
|
|
57 | (6) |
|
Web Assistant Wizard and Internet Enabling |
|
|
57 | (1) |
|
|
|
58 | (1) |
|
SQL Server Service Manager |
|
|
59 | (1) |
|
System Monitor Integration |
|
|
60 | (1) |
|
|
|
60 | (1) |
|
|
|
61 | (1) |
|
|
|
61 | (1) |
|
|
|
61 | (1) |
|
|
|
61 | (1) |
|
Bulk Copy and Data Transformation Services |
|
|
62 | (1) |
|
|
|
63 | (1) |
|
|
|
63 | (1) |
|
Client Development Interfaces |
|
|
63 | (3) |
|
|
|
64 | (1) |
|
|
|
64 | (1) |
|
|
|
64 | (1) |
|
|
|
65 | (1) |
|
|
|
65 | (1) |
|
Server Development Interface |
|
|
65 | (1) |
|
|
|
66 | (3) |
| Part II Architectural Overview |
|
|
|
|
69 | (46) |
|
|
|
69 | (22) |
|
|
|
70 | (4) |
|
|
|
74 | (3) |
|
The Relational Engine and the Storage Engine |
|
|
77 | (4) |
|
The Access Methods Manager |
|
|
81 | (1) |
|
The Row Operations Manager and the Index Manager |
|
|
82 | (4) |
|
The Page Manager and the Text Manager |
|
|
86 | (1) |
|
|
|
87 | (3) |
|
|
|
90 | (1) |
|
|
|
91 | (1) |
|
|
|
91 | (10) |
|
The Buffer Manager and Memory Pools |
|
|
92 | (1) |
|
Access to In-Memory Pages |
|
|
92 | (1) |
|
Access to Free Pages (Lazywriter) |
|
|
93 | (2) |
|
|
|
95 | (2) |
|
Accessing Pages Using the Buffer Manager |
|
|
97 | (1) |
|
|
|
97 | (4) |
|
|
|
101 | (1) |
|
Transaction Logging and Recovery |
|
|
101 | (5) |
|
|
|
104 | (1) |
|
|
|
104 | (2) |
|
The SQL Server Kernel and Interaction with the Operating System |
|
|
106 | (5) |
|
Threading and Symmetric Multiprocessing |
|
|
107 | (2) |
|
|
|
109 | (2) |
|
Disk I/O in Windows NT/2000 |
|
|
111 | (1) |
|
|
|
111 | (4) |
| Part III Using Microsoft SQL Server |
|
|
Planning for and Installing SQL Server |
|
|
115 | (56) |
|
|
|
116 | (3) |
|
|
|
119 | (1) |
|
|
|
119 | (2) |
|
Use Hardware on the Windows Hardware Compatibility List |
|
|
119 | (1) |
|
Performance = Fn (Processor Cycles, Memory, I/O Throughput) |
|
|
120 | (1) |
|
|
|
121 | (1) |
|
|
|
121 | (20) |
|
|
|
122 | (2) |
|
|
|
124 | (1) |
|
Disk Drives, Controllers, and Disk Arrays |
|
|
125 | |
|
|
|
120 | (17) |
|
More About Drives and Controllers |
|
|
137 | (1) |
|
Uninterruptible Power Supply |
|
|
138 | (1) |
|
|
|
139 | (1) |
|
Fallback Server Capability |
|
|
140 | (1) |
|
Other Hardware Considerations |
|
|
141 | (1) |
|
|
|
141 | (1) |
|
|
|
142 | (1) |
|
Security and the User Context |
|
|
143 | (2) |
|
|
|
145 | (5) |
|
SQL Server Processor License |
|
|
145 | (1) |
|
|
|
145 | (1) |
|
Multiplexing: Use of Middleware, Transaction Servers, and Multitiered Architectures |
|
|
146 | (1) |
|
|
|
147 | (3) |
|
|
|
150 | (1) |
|
|
|
150 | (7) |
|
|
|
151 | (1) |
|
|
|
152 | (5) |
|
|
|
157 | (3) |
|
Installing Named Instances |
|
|
158 | (1) |
|
Named Instance Server Connectivity |
|
|
159 | (1) |
|
|
|
160 | (2) |
|
Upgrading from a Previous Version |
|
|
161 | (1) |
|
Basic Configuration After Installation |
|
|
162 | (4) |
|
Starting the SQL Server Service |
|
|
162 | (1) |
|
Changing the System Administrator Password |
|
|
163 | (1) |
|
Configuring SQL Server's Error Log |
|
|
164 | (1) |
|
Working with Multiple Instances |
|
|
164 | (2) |
|
Remote and Unattended Installation |
|
|
166 | (4) |
|
|
|
167 | (1) |
|
|
|
167 | (1) |
|
Changing Installation Options |
|
|
168 | (1) |
|
Adding Additional Components |
|
|
169 | (1) |
|
|
|
170 | (1) |
|
Databases and Database Files |
|
|
171 | (50) |
|
|
|
172 | (3) |
|
|
|
172 | (1) |
|
|
|
173 | (1) |
|
|
|
173 | (1) |
|
|
|
174 | (1) |
|
|
|
174 | (1) |
|
|
|
175 | (1) |
|
|
|
175 | (1) |
|
|
|
176 | (3) |
|
A Create Database Example |
|
|
178 | (1) |
|
Expanding and Shrinking a Database |
|
|
179 | (3) |
|
|
|
179 | (1) |
|
|
|
179 | (1) |
|
|
|
179 | (1) |
|
|
|
180 | (2) |
|
|
|
182 | (4) |
|
|
|
185 | (1) |
|
Using Database Filegroups |
|
|
186 | (4) |
|
|
|
187 | (2) |
|
A Filegroup Creation Example |
|
|
189 | (1) |
|
|
|
190 | (2) |
|
|
|
191 | (1) |
|
|
|
192 | (5) |
|
|
|
194 | (3) |
|
|
|
197 | (8) |
|
|
|
198 | (4) |
|
|
|
202 | (1) |
|
|
|
202 | (1) |
|
|
|
203 | (2) |
|
|
|
205 | (1) |
|
Other Database Considerations |
|
|
205 | (4) |
|
|
|
205 | (1) |
|
|
|
206 | (1) |
|
Detaching and Reattaching a Database |
|
|
207 | (1) |
|
|
|
208 | (1) |
|
Backing Up and Restoring a Database |
|
|
209 | (10) |
|
|
|
210 | (1) |
|
|
|
211 | (3) |
|
|
|
214 | (1) |
|
|
|
215 | (4) |
|
|
|
219 | (2) |
|
|
|
221 | (96) |
|
|
|
222 | (17) |
|
Naming Tables and Columns |
|
|
223 | (1) |
|
|
|
224 | (1) |
|
|
|
224 | (1) |
|
|
|
225 | (1) |
|
|
|
226 | (9) |
|
|
|
235 | (4) |
|
|
|
239 | (2) |
|
|
|
241 | (4) |
|
|
|
245 | (25) |
|
|
|
246 | (2) |
|
|
|
248 | (4) |
|
The Structure of Data Rows |
|
|
252 | (2) |
|
|
|
254 | (1) |
|
Storage of Fixed-Length and Variable-Length Rows |
|
|
255 | (4) |
|
|
|
259 | (1) |
|
|
|
260 | (6) |
|
|
|
266 | (4) |
|
|
|
270 | (36) |
|
Primary Key and Unique Constraints |
|
|
271 | (6) |
|
|
|
277 | (9) |
|
Constraint-Checking Solutions |
|
|
286 | (1) |
|
Restrictions on Dropping Tables |
|
|
287 | (1) |
|
|
|
287 | (2) |
|
|
|
289 | (5) |
|
|
|
294 | (4) |
|
|
|
298 | (8) |
|
|
|
306 | (3) |
|
|
|
306 | (2) |
|
|
|
308 | (1) |
|
Adding, Dropping, Disabling, or Enabling a Constraint |
|
|
308 | (1) |
|
|
|
309 | (1) |
|
Enabling or Disabling a Trigger |
|
|
309 | (1) |
|
|
|
309 | (3) |
|
Private Temporary Tables (#) |
|
|
310 | (1) |
|
Global Temporary Tables (##) |
|
|
310 | (1) |
|
|
|
311 | (1) |
|
Constraints on Temporary Tables |
|
|
311 | (1) |
|
|
|
312 | (3) |
|
|
|
315 | (2) |
|
|
|
317 | (86) |
|
|
|
317 | (3) |
|
|
|
320 | (16) |
|
|
|
324 | (5) |
|
The Obsolete *= Outer Join Operator |
|
|
329 | (6) |
|
|
|
335 | (1) |
|
|
|
336 | (9) |
|
|
|
340 | (3) |
|
|
|
343 | (2) |
|
|
|
345 | (12) |
|
|
|
350 | (7) |
|
|
|
357 | (8) |
|
|
|
361 | (1) |
|
|
|
362 | (3) |
|
|
|
365 | (36) |
|
|
|
365 | (6) |
|
|
|
371 | (1) |
|
|
|
371 | (7) |
|
Datacube---Aggregate Variations |
|
|
378 | (14) |
|
|
|
392 | (3) |
|
|
|
395 | (6) |
|
|
|
401 | (2) |
|
|
|
403 | (46) |
|
|
|
404 | (4) |
|
|
|
406 | (1) |
|
|
|
406 | (2) |
|
|
|
408 | (3) |
|
|
|
410 | (1) |
|
The Structure of Index Pages |
|
|
411 | (16) |
|
Clustered Index Rows with a Uniqueifier |
|
|
412 | (3) |
|
|
|
415 | (12) |
|
|
|
427 | (4) |
|
|
|
427 | (1) |
|
Actual vs. Estimated Size |
|
|
428 | (3) |
|
|
|
431 | (6) |
|
|
|
431 | (1) |
|
|
|
432 | (3) |
|
|
|
435 | (2) |
|
|
|
437 | (9) |
|
|
|
437 | (4) |
|
Indexes on Computed Columns |
|
|
441 | (2) |
|
|
|
443 | (3) |
|
|
|
446 | (2) |
|
|
|
446 | (1) |
|
|
|
446 | (1) |
|
|
|
446 | (2) |
|
|
|
448 | (1) |
|
|
|
448 | (1) |
|
|
|
448 | (1) |
|
|
|
449 | (50) |
|
Basic Modification Operations |
|
|
449 | (27) |
|
|
|
450 | (13) |
|
|
|
463 | (2) |
|
|
|
465 | (2) |
|
Modifying Data Through Views |
|
|
467 | (9) |
|
Data Modification Internals |
|
|
476 | (22) |
|
|
|
477 | (1) |
|
|
|
477 | (4) |
|
|
|
481 | (8) |
|
|
|
489 | (6) |
|
Table-Level vs. Index-Level Data Modification |
|
|
495 | (2) |
|
|
|
497 | (1) |
|
|
|
497 | (1) |
|
|
|
498 | (1) |
|
Programming with Transact-SQL |
|
|
499 | (100) |
|
Transact-SQL As A Programming Language |
|
|
500 | (3) |
|
Programming at Multiple Levels |
|
|
501 | (2) |
|
Transact-SQL Programming Constructs |
|
|
503 | (60) |
|
|
|
503 | (7) |
|
|
|
510 | (1) |
|
|
|
511 | (3) |
|
|
|
514 | (1) |
|
|
|
515 | (3) |
|
|
|
518 | (1) |
|
|
|
519 | (8) |
|
|
|
527 | (35) |
|
|
|
562 | (1) |
|
Transact-SQL Examples and Brainteasers |
|
|
563 | (16) |
|
|
|
563 | (4) |
|
|
|
567 | (6) |
|
Finding Differences Between Intervals |
|
|
573 | (5) |
|
Selecting Instead of Iterating |
|
|
578 | (1) |
|
|
|
579 | (19) |
|
|
|
581 | (1) |
|
Setting Up Full-Text Indexes |
|
|
582 | (3) |
|
Maintaining Full-Text Indexes |
|
|
585 | (4) |
|
Querying Full-Text Indexes |
|
|
589 | (8) |
|
Performance Considerations for Full-Text Indexes |
|
|
597 | (1) |
|
|
|
598 | (1) |
|
Batches, Stored Procedures, and Functions |
|
|
599 | (58) |
|
|
|
600 | (4) |
|
|
|
604 | (1) |
|
|
|
605 | (12) |
|
|
|
607 | (1) |
|
Recursion in Stored Procedures |
|
|
608 | (5) |
|
Stored Procedure Parameters |
|
|
613 | (4) |
|
|
|
617 | (10) |
|
|
|
61 | (557) |
|
|
|
618 | (3) |
|
|
|
621 | (3) |
|
System Table-Valued Functions |
|
|
624 | (1) |
|
Managing User-Defined Functions |
|
|
624 | (3) |
|
Rewriting Stored Procedures as Functions |
|
|
627 | (1) |
|
Rolling Your Own System Routines |
|
|
628 | (4) |
|
Your Own System Procedures |
|
|
628 | (2) |
|
Your Own System Functions |
|
|
630 | (2) |
|
Executing Batches, or What's Stored about Stored Procedures (and Functions)? |
|
|
632 | (8) |
|
Parse Commands and Create the Sequence Tree |
|
|
632 | (1) |
|
|
|
632 | (1) |
|
|
|
632 | (2) |
|
Recompile Execution Plans |
|
|
634 | (2) |
|
|
|
636 | (1) |
|
|
|
637 | (3) |
|
|
|
640 | (1) |
|
Temporary Stored Procedures |
|
|
640 | (2) |
|
Private Temporary Stored Procedures |
|
|
640 | (1) |
|
Global Temporary Stored Procedures |
|
|
641 | (1) |
|
Procedures Created from Direct Use of tempdb |
|
|
641 | (1) |
|
Autostart Stored Procedures |
|
|
642 | (1) |
|
|
|
643 | (10) |
|
General System Procedures |
|
|
644 | (1) |
|
Catalog Stored Procedures |
|
|
645 | (1) |
|
SQL Server Agent Stored Procedures |
|
|
646 | (1) |
|
Replication Stored Procedures |
|
|
646 | (1) |
|
Extended Stored Procedures |
|
|
647 | (6) |
|
|
|
653 | (2) |
|
|
|
655 | (2) |
|
Transactions and Triggers |
|
|
657 | (46) |
|
|
|
657 | (25) |
|
Explicit and Implicit Transactions |
|
|
659 | (1) |
|
Error Checking in Transactions |
|
|
660 | (6) |
|
Transaction Isolation Levels |
|
|
666 | (10) |
|
Other Characteristics of Transactions |
|
|
676 | (1) |
|
Nested Transaction Blocks |
|
|
677 | (4) |
|
|
|
681 | (1) |
|
|
|
682 | (19) |
|
|
|
682 | (6) |
|
|
|
688 | (4) |
|
|
|
692 | (1) |
|
Using Triggers to Implement Referential Actions |
|
|
692 | (8) |
|
|
|
700 | (1) |
|
|
|
701 | (2) |
|
Special Transact-SQL Operations: Working with Cursors and Large Objects |
|
|
703 | (70) |
|
|
|
704 | (3) |
|
|
|
707 | (4) |
|
Problems with ISAM-Style Applications |
|
|
710 | (1) |
|
|
|
711 | (4) |
|
|
|
711 | (1) |
|
|
|
712 | (1) |
|
|
|
713 | (1) |
|
|
|
714 | (1) |
|
API Server Cursors vs. Transact-SQL Cursors |
|
|
714 | (1) |
|
Appropriate Use of Cursors |
|
|
715 | (10) |
|
|
|
716 | (1) |
|
|
|
716 | (1) |
|
|
|
717 | (1) |
|
|
|
718 | (2) |
|
Cursor Membership, Scrolling, and Sensitivity to Change |
|
|
720 | (5) |
|
Working with Transact-SQL Cursors |
|
|
725 | (18) |
|
|
|
726 | (2) |
|
|
|
728 | (1) |
|
|
|
729 | (1) |
|
|
|
730 | (1) |
|
|
|
731 | (1) |
|
|
|
731 | (1) |
|
|
|
732 | (1) |
|
The Simplest Cursor Syntax |
|
|
732 | (1) |
|
Fully Scrollable Transact-SQL Cursors |
|
|
732 | (3) |
|
Concurrency Control with Transact-SQL Cursors |
|
|
735 | (8) |
|
|
|
743 | (7) |
|
Obtaining Cursor Information |
|
|
744 | (6) |
|
Working with Text and Image Data |
|
|
750 | (19) |
|
|
|
752 | (3) |
|
|
|
755 | (6) |
|
|
|
761 | (8) |
|
|
|
769 | (4) |
| Part IV Performance and Tuning |
|
|
|
|
773 | (42) |
|
|
|
773 | (6) |
|
The Lock Manager and Isolation Levels |
|
|
774 | (1) |
|
|
|
775 | (1) |
|
|
|
775 | (4) |
|
|
|
779 | (19) |
|
|
|
780 | (1) |
|
|
|
780 | (10) |
|
|
|
790 | (1) |
|
|
|
790 | (1) |
|
|
|
791 | (7) |
|
|
|
798 | (2) |
|
Internal Locking Architecture |
|
|
800 | (7) |
|
|
|
802 | (2) |
|
|
|
804 | (1) |
|
|
|
804 | (3) |
|
|
|
807 | (4) |
|
Row-Level vs. Page-Level Locking |
|
|
811 | (2) |
|
|
|
812 | (1) |
|
Locking Hints and Trace Flags |
|
|
813 | (1) |
|
|
|
813 | (2) |
|
|
|
815 | (52) |
|
|
|
816 | (1) |
|
Compilation and Optimization |
|
|
816 | (36) |
|
|
|
817 | (1) |
|
|
|
818 | (2) |
|
How the Query Optimizer Works |
|
|
820 | (19) |
|
|
|
839 | (6) |
|
Other Processing Strategies |
|
|
845 | (1) |
|
|
|
846 | (6) |
|
|
|
852 | (3) |
|
Using Stored Procedures and Caching Mechanisms |
|
|
855 | (10) |
|
|
|
856 | (1) |
|
|
|
856 | (1) |
|
The sp_executesql Procedure |
|
|
857 | (1) |
|
The Prepare and Execute Method |
|
|
857 | (1) |
|
|
|
857 | (1) |
|
|
|
858 | (2) |
|
|
|
860 | (2) |
|
When to Use Stored Procedures and Other Caching Mechanisms |
|
|
862 | (1) |
|
Recompiling Stored Procedures |
|
|
862 | (1) |
|
Other Benefits of Stored Procedures |
|
|
863 | (2) |
|
|
|
865 | (1) |
|
|
|
865 | (2) |
|
|
|
867 | (76) |
|
|
|
868 | (1) |
|
Application and Database Design |
|
|
868 | (6) |
|
|
|
869 | (2) |
|
Evaluate Your Critical Transactions |
|
|
871 | (2) |
|
Keep Table Row Lengths and Keys Compact |
|
|
873 | (1) |
|
|
|
874 | (1) |
|
Perceived Response Time for Interactive Systems |
|
|
874 | (2) |
|
Prototyping, Benchmarking, and Testing |
|
|
876 | (4) |
|
Development Methodologies |
|
|
878 | (2) |
|
|
|
880 | (9) |
|
Choose the Clustered Index Carefully |
|
|
881 | (1) |
|
Make Nonclustered Indexes Highly Selective |
|
|
882 | (1) |
|
Tailor Indexes to Critical Transactions |
|
|
883 | (2) |
|
Pay Attention to Column Order |
|
|
885 | (1) |
|
Index Columns Used in Joins |
|
|
885 | (2) |
|
Create or Drop Indexes as Needed |
|
|
887 | (1) |
|
|
|
887 | (2) |
|
Monitoring Query Performance |
|
|
889 | (25) |
|
|
|
889 | (4) |
|
|
|
893 | (1) |
|
|
|
893 | (15) |
|
|
|
908 | (4) |
|
Stored Procedure Optimization |
|
|
912 | (2) |
|
Concurrency and Consistency Tradeoffs |
|
|
914 | (1) |
|
Resolving Blocking Problems |
|
|
915 | (4) |
|
|
|
917 | (2) |
|
Resolving Deadlock Problems |
|
|
919 | (15) |
|
|
|
919 | (1) |
|
Conversion Deadlock Example |
|
|
919 | (3) |
|
|
|
922 | (1) |
|
|
|
922 | (1) |
|
Volunteering to Be the Deadlock Victim |
|
|
923 | (1) |
|
Watching Locking Activity |
|
|
923 | (1) |
|
|
|
924 | (7) |
|
|
|
931 | (3) |
|
Segregating OLTP and DSS Applications |
|
|
934 | (1) |
|
|
|
935 | (7) |
|
|
|
935 | (1) |
|
Nullability and ANSI Compliance Settings |
|
|
936 | (6) |
|
Locale-Specific SET Options |
|
|
942 | (1) |
|
|
|
942 | (1) |
|
Configuration and Performance Monitoring |
|
|
943 | (44) |
|
Operating System Configuration Settings |
|
|
944 | (2) |
|
|
|
944 | (1) |
|
|
|
944 | (1) |
|
|
|
945 | (1) |
|
|
|
945 | (1) |
|
|
|
946 | (1) |
|
|
|
946 | (1) |
|
SQL Server Configuration Settings |
|
|
946 | (14) |
|
|
|
947 | (11) |
|
|
|
958 | (2) |
|
Startup Parameters on SQLSERVR.EXE |
|
|
960 | (1) |
|
|
|
960 | (1) |
|
Monitoring System Behavior |
|
|
961 | (24) |
|
|
|
961 | (15) |
|
|
|
976 | (9) |
|
Other Performance Monitoring Considerations |
|
|
985 | (1) |
|
|
|
985 | (2) |
| Bibliography and Suggested Reading |
|
987 | (6) |
| Index |
|
993 | |