Introduction |
|
xix | |
Chapter 1 Background to T-SQL querying and programming |
|
1 | (26) |
|
|
1 | (11) |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
4 | (1) |
|
|
4 | (6) |
|
Types of database systems |
|
|
10 | (2) |
|
|
12 | (7) |
|
The ABCs of Microsoft RDBMS flavors |
|
|
12 | (2) |
|
|
14 | (1) |
|
|
15 | (3) |
|
|
18 | (1) |
|
Creating tables and defining data integrity |
|
|
19 | (6) |
|
|
20 | (2) |
|
|
22 | (3) |
|
|
25 | (2) |
Chapter 2 Single-table queries |
|
27 | (76) |
|
Elements of the SELECT statement |
|
|
27 | (22) |
|
|
29 | (2) |
|
|
31 | (1) |
|
|
32 | (3) |
|
|
35 | (1) |
|
|
36 | (5) |
|
|
41 | (2) |
|
The TOP and OFFSET-FETCH filters |
|
|
43 | (4) |
|
A quick look at window functions |
|
|
47 | (2) |
|
|
49 | (3) |
|
|
52 | (2) |
|
|
54 | (4) |
|
|
58 | (2) |
|
Working with character data |
|
|
60 | (13) |
|
|
60 | (1) |
|
|
61 | (2) |
|
|
63 | (8) |
|
|
71 | (2) |
|
Working with date and time data |
|
|
73 | (16) |
|
|
74 | (1) |
|
|
74 | (4) |
|
Working with date and time separately |
|
|
78 | (1) |
|
|
79 | (1) |
|
|
80 | (9) |
|
|
89 | (4) |
|
|
90 | (1) |
|
|
91 | (1) |
|
System stored procedures and functions |
|
|
91 | (2) |
|
|
93 | (1) |
|
|
93 | (4) |
|
|
93 | (1) |
|
|
93 | (1) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
95 | (1) |
|
|
95 | (1) |
|
|
96 | (1) |
|
|
96 | (1) |
|
|
97 | (1) |
|
|
97 | (6) |
|
|
98 | (1) |
|
|
98 | (1) |
|
|
99 | (1) |
|
|
99 | (1) |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (1) |
|
|
102 | (1) |
|
|
102 | (1) |
Chapter 3 Joins |
|
103 | (30) |
|
|
103 | (4) |
|
|
104 | (1) |
|
|
105 | (1) |
|
|
105 | (1) |
|
Producing tables of numbers |
|
|
106 | (1) |
|
|
107 | (2) |
|
|
107 | (1) |
|
|
108 | (1) |
|
|
109 | (1) |
|
|
109 | (4) |
|
|
110 | (1) |
|
|
111 | (2) |
|
|
113 | (1) |
|
|
113 | (10) |
|
Fundamentals of outer joins |
|
|
114 | (2) |
|
Beyond the fundamentals of outer joins |
|
|
116 | (7) |
|
|
123 | (1) |
|
|
123 | (6) |
|
|
123 | (1) |
|
Exercise 1-2 (optional, advanced) |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
Exercise 7 (optional, advanced) |
|
|
127 | (1) |
|
Exercise 8 (optional, advanced) |
|
|
128 | (1) |
|
Exercise 9 (optional, advanced) |
|
|
128 | (1) |
|
|
129 | (4) |
|
|
129 | (1) |
|
|
129 | (1) |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
131 | (1) |
|
|
132 | (1) |
|
|
132 | (1) |
Chapter 4 Subqueries |
|
133 | (28) |
|
Self-contained subqueries |
|
|
133 | (6) |
|
Self-contained scalar subquery examples |
|
|
134 | (2) |
|
Self-contained multivalued subquery examples |
|
|
136 | (3) |
|
|
139 | (4) |
|
|
141 | (2) |
|
Beyond the fundamentals of subqueries |
|
|
143 | (6) |
|
Returning previous or next values |
|
|
143 | (1) |
|
|
144 | (1) |
|
Dealing with misbehaving subqueries |
|
|
145 | (4) |
|
|
149 | (1) |
|
|
150 | (4) |
|
|
150 | (1) |
|
Exercise 2 (optional, advanced) |
|
|
150 | (1) |
|
|
151 | (1) |
|
|
151 | (1) |
|
|
152 | (1) |
|
|
152 | (1) |
|
Exercise 7 (optional, advanced) |
|
|
153 | (1) |
|
Exercise 8 (optional, advanced) |
|
|
153 | (1) |
|
|
154 | (1) |
|
Exercise 10 (optional, advanced) |
|
|
154 | (1) |
|
|
154 | (7) |
|
|
154 | (1) |
|
|
155 | (1) |
|
|
155 | (1) |
|
|
155 | (1) |
|
|
156 | (1) |
|
|
156 | (1) |
|
|
156 | (1) |
|
|
157 | (1) |
|
|
157 | (1) |
|
|
158 | (3) |
Chapter 5 Table expressions |
|
161 | (32) |
|
|
161 | (6) |
|
|
163 | (1) |
|
|
164 | (1) |
|
|
165 | (1) |
|
|
166 | (1) |
|
|
167 | (4) |
|
Assigning column aliases in CTEs |
|
|
167 | (1) |
|
|
168 | (1) |
|
|
168 | (1) |
|
Multiple references in CTEs |
|
|
169 | (1) |
|
|
169 | (2) |
|
|
171 | (7) |
|
Views and the ORDER BY clause |
|
|
172 | (3) |
|
|
175 | (3) |
|
Inline table-valued functions |
|
|
178 | (2) |
|
|
180 | (3) |
|
|
183 | (1) |
|
|
183 | (5) |
|
|
183 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
|
185 | (1) |
|
Exercise 4 (optional, advanced) |
|
|
185 | (1) |
|
|
186 | (1) |
|
Exercise 5-2 (optional, advanced) |
|
|
187 | (1) |
|
|
187 | (1) |
|
|
188 | (1) |
|
|
188 | (5) |
|
|
188 | (1) |
|
|
189 | (1) |
|
|
189 | (1) |
|
|
189 | (1) |
|
|
189 | (1) |
|
|
190 | (1) |
|
|
190 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
192 | (1) |
Chapter 6 Set operators |
|
193 | (20) |
|
|
194 | (2) |
|
|
194 | (1) |
|
The UNION (DISTINCT) operator |
|
|
195 | (1) |
|
|
196 | (3) |
|
The INTERSECT (DISTINCT) operator |
|
|
196 | (1) |
|
The INTERSECT ALL operator |
|
|
197 | (2) |
|
|
199 | (2) |
|
The EXCEPT (DISTINCT) operator |
|
|
199 | (1) |
|
|
200 | (1) |
|
|
201 | (2) |
|
Circumventing unsupported logical phases |
|
|
203 | (1) |
|
|
204 | (1) |
|
|
204 | (4) |
|
|
204 | (1) |
|
|
205 | (1) |
|
|
205 | (1) |
|
|
206 | (1) |
|
|
207 | (1) |
|
Exercise 6 (optional, advanced) |
|
|
207 | (1) |
|
|
208 | (5) |
|
|
208 | (1) |
|
|
208 | (1) |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
211 | (2) |
Chapter 7 Beyond the fundamentals of querying |
|
213 | (36) |
|
|
213 | (11) |
|
|
216 | (3) |
|
|
219 | (2) |
|
Aggregate window functions |
|
|
221 | (3) |
|
|
224 | (6) |
|
Pivoting with a grouped query |
|
|
226 | (1) |
|
Pivoting with the PIVOT operator |
|
|
227 | (3) |
|
|
230 | (4) |
|
Unpivoting with the APPLY operator |
|
|
231 | (2) |
|
Unpivoting with the UNPIVOT operator |
|
|
233 | (1) |
|
|
234 | (6) |
|
The GROUPING SETS subclause |
|
|
236 | (1) |
|
|
236 | (1) |
|
|
236 | (2) |
|
The GROUPING and GROUPING ID functions |
|
|
238 | (2) |
|
|
240 | (1) |
|
|
241 | (4) |
|
|
241 | (1) |
|
|
241 | (1) |
|
|
242 | (1) |
|
|
242 | (1) |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
245 | (4) |
|
|
245 | (1) |
|
|
245 | (1) |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
247 | (1) |
|
|
247 | (2) |
Chapter 8 Data modification |
|
249 | (48) |
|
|
249 | (13) |
|
The INSERT VALUES statement |
|
|
249 | (2) |
|
The INSERT SELECT statement |
|
|
251 | (1) |
|
The INSERT EXEC statement |
|
|
251 | (1) |
|
The SELECT INTO statement |
|
|
252 | (1) |
|
The BULK INSERT statement |
|
|
253 | (1) |
|
The identity property and the sequence object |
|
|
254 | (8) |
|
|
262 | (4) |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
265 | (1) |
|
|
266 | (5) |
|
|
267 | (1) |
|
|
268 | (2) |
|
|
270 | (1) |
|
|
271 | (5) |
|
Modifying data through table expressions |
|
|
276 | (2) |
|
Modifications with TOP and OFFSET-FETCH |
|
|
278 | (2) |
|
|
280 | (7) |
|
|
280 | (2) |
|
|
282 | (1) |
|
|
283 | (1) |
|
|
284 | (1) |
|
|
285 | (2) |
|
|
287 | (1) |
|
|
287 | (4) |
|
|
287 | (1) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
288 | (2) |
|
|
290 | (1) |
|
|
290 | (1) |
|
|
291 | (6) |
|
|
291 | (2) |
|
|
293 | (1) |
|
|
293 | (1) |
|
|
294 | (1) |
|
|
294 | (1) |
|
|
295 | (2) |
Chapter 9 Temporal tables |
|
297 | (22) |
|
|
298 | (3) |
|
|
301 | (3) |
|
|
304 | (7) |
|
|
311 | (1) |
|
|
311 | (2) |
|
|
311 | (1) |
|
|
311 | (1) |
|
|
312 | (1) |
|
|
313 | (1) |
|
|
313 | (6) |
|
|
313 | (1) |
|
|
314 | (2) |
|
|
316 | (1) |
|
|
317 | (2) |
Chapter 10 Transactions and concurrency |
|
319 | (42) |
|
|
319 | (3) |
|
|
322 | (10) |
|
|
322 | (3) |
|
|
325 | (7) |
|
|
332 | (13) |
|
The READ UNCOMMITTED isolation level |
|
|
333 | (1) |
|
The READ COMMITTED isolation level |
|
|
334 | (1) |
|
The REPEATABLE READ isolation level |
|
|
335 | (2) |
|
The SERIALIZABLE isolation level |
|
|
337 | (2) |
|
Isolation levels based on row versioning |
|
|
339 | (6) |
|
Summary of isolation levels |
|
|
345 | (1) |
|
|
345 | (3) |
|
|
348 | (1) |
|
|
348 | (13) |
|
|
349 | (1) |
|
|
349 | (1) |
|
|
349 | (1) |
|
|
349 | (1) |
|
|
350 | (1) |
|
|
350 | (1) |
|
|
350 | (1) |
|
|
351 | (1) |
|
|
352 | (1) |
|
|
353 | (1) |
|
|
354 | (2) |
|
|
356 | (1) |
|
|
357 | (1) |
|
|
358 | (1) |
|
|
358 | (1) |
|
|
358 | (1) |
|
|
358 | (1) |
|
|
358 | (1) |
|
|
359 | (2) |
Chapter 11 Programmable objects |
|
361 | (34) |
|
|
361 | (2) |
|
|
363 | (4) |
|
A batch as a unit of parsing |
|
|
364 | (1) |
|
|
365 | (1) |
|
Statements that cannot be combined in the same batch |
|
|
365 | (1) |
|
A batch as a unit of resolution |
|
|
366 | (1) |
|
|
366 | (1) |
|
|
367 | (3) |
|
The IF... ELSE flow element |
|
|
367 | (1) |
|
|
368 | (2) |
|
|
370 | (4) |
|
|
374 | (5) |
|
|
374 | (2) |
|
|
376 | (1) |
|
|
377 | (1) |
|
|
378 | (1) |
|
|
379 | (4) |
|
|
380 | (1) |
|
The sp executesql stored procedure |
|
|
380 | (1) |
|
Using PIVOT with Dynamic SQL |
|
|
381 | (2) |
|
|
383 | (7) |
|
|
383 | (2) |
|
|
385 | (2) |
|
|
387 | (3) |
|
|
390 | (4) |
|
|
394 | (1) |
Appendix: Getting started |
|
395 | (20) |
Index |
|
415 | |