Microsoft KB Archive/920141

= Inside Microsoft SQL Server 2005: T-SQL Querying comments and corrections =

Article ID: 920141

Article Last Modified on 10/24/2007

-

APPLIES TO


 * Inside Microsoft SQL Server 2005: T-SQL Querying, ISBN 0-7356-2313-9

-



SUMMARY
This article contains comments, corrections, and information about known errors relating to the Microsoft Press book Inside Microsoft SQL Server 2005: T-SQL Querying, 0-7356-2313-9.

The following topics are covered:


 * Page 8: Correction to table keys
 * Page 20:  tag used in place of  tag
 * Page 43: Yes missing from Figure 2-7
 * Page 51: Link in MoreInfo box is incorrect
 * Page 68: THEN repeated in code sample
 * Page 73: &quot;signal_wait_time&quot; should be &quot;signal_wait_time_ms&quot;
 * Page 81: Missing spaces in Table 3-3
 * Page 101: &quot;1000&quot; used in place of &quot;1000000&quot;
 * Pages 102, 103: &quot;1000&quot; used in place of &quot;1000000&quot;
 * Page 137: Ordered scan referenced rather than unordered scan
 * Page 139: &quot;not used&quot; should be &quot;used not&quot;
 * Page 140: The second orderid should be 120 in the sixth sentence of the paragraph following the query
 * Page 141: Index Scan referenced in place of Index Seek
 * Page 158: The term &quot;grows larger&quot; is used instead of the term &quot;gets lower&quot;
 * Page 162: The third line from the top needs UNIQUE removed and orderdate replacing orderid
 * Pages 163-166: Unordered Nonclustered Index Scan referred to as Unordered Covering Nonclustered Index Scan
 * Page 168: &quot;scan fragmentation&quot; should be &quot;page density&quot;
 * Page 173: Customer information referenced rather than session information
 * Page 173: Listing 3-7 table name should be BigSessions instead of sessions
 * Page 187: &quot;yes&quot; should be &quot;no&quot;
 * Page 192: Correction in fourth paragraph subquery example instructions
 * Page 203: Variable b referenced in place of variable c
 * Page 203: &quot;EXISTS&quot; should be &quot;NOT EXISTS&quot;
 * Page 206: &quot;MIN(keycol) + 1&quot; should be &quot;MIN(keycol + 1)&quot;
 * Page 272: &quot;ranking functions&quot; and &quot;recursive queries&quot; referred to rather than &quot;PIVOT&quot; and &quot;UNPIVOT&quot;
 * Page 328: &quot;running&quot; should be &quot;sliding&quot;
 * Page 340: Yearly Quantities refered to rather than Yearly Orders in the caption for Table 6-16
 * Page 356: period missing from attribute
 * Page 364: Incorrect labels for the second and third columns of Table 6-24
 * Page 364: Incorrect labels for the second and third columns of Table 6-25
 * Page 412: &quot;2147483648&quot; should be &quot;-2147483648&quot;
 * Pages 431 and 432: #CustStage referred to rather than #CustsStage
 * Page 434: usp_AsyncSec refered to rather than usp_AsyncSeq
 * Page 445: Incorrect SET statement in the first code sample
 * Page 445: &quot;many&quot; should be &quot;one&quot;
 * Page 480: fn_subordinates2 referenced in place of fn_subordinates1
 * Page 485: < should be <=
 * Page 493: &quot;SubsPath&quot; should be &quot;SubsSort&quot;
 * Page 494: @ should be #
 * Page 506: Incorrect use of apostrophe
 * Page 513: Reference to Table 9-35 should be more specific
 * Page 533: &quot;BOMCTE&quot; should be &quot;BOMTC&quot;
 * Page 562: Lamp 36 missing from the list of lamps that are on
 * Page 567: Corretion to Puzzle 19 answer



Page 8: Correction to table keys
On page 8, at the bottom of sidebar, there is an error.

Change:

“On the other hand, UNIQUE and PRIMARY KEY constraints, sorting, and grouping treat NULLs as equal: You cannot insert into a table two rows with a NULL in a column that has a UNIQUE or PRIMARY KEY constraint defined on it.”

To:

“On the other hand, a UNIQUE constraint, sorting, and grouping treat NULLs as equal: You cannot insert into a table two rows with a NULL in a column that has a UNIQUE constraint defined on it.”

Page 20:  tag used in place of  tag
On page 20, the second line of the second table operator reads:

{CROSS | OUTER} APPLY 

It should read:

{CROSS | OUTER} APPLY 

Page 43: Yes missing from Figure 2-7
On page 43, in Figure 2-7, there should be a &quot;Yes&quot; above the arrow pointing from &quot;Does query qualify for parallel plan?&quot; to &quot;Phase 1 parallel plan&quot;.

Page 51: Link in MoreInfo box is incorrect
On page 51, the first sentence inside the MoreInfo box contains a link that needs to be changed.

Change:

&quot;A good example of extracting data from the XML showplan can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/xmlshowplans.asp.&quot;

To:

&quot;A good example of extracting data from the XML showplan can be found at http://msdn2.microsoft.com/en-us/library/ms345130.aspx.&quot;

Page 68: THEN repeated in code sample
On page 68, lines 32-35 in the code sample reads:

- CASE WHEN n % 10 = 0 THEN THEN 1 + ABS(CHECKSUM(NEWID)) % 30 ELSE 0 END AS orderdate

It should read:

- CASE WHEN n % 10 = 0 THEN 1 + ABS(CHECKSUM(NEWID)) % 30 ELSE 0 END AS orderdate

Page 73: &quot;signal_wait_time&quot; should be &quot;signal_wait_time_ms&quot;
On page 73, the last paragraph on the page contains an incorrect wait_time.

Change:

&quot;The DMV sys.dm_os_wait_stats contains the following attributes: wait_type; waiting_tasks_count, which is the number of waits on this wait type; wait_time_ms, which is total wait time for this wait type in milliseconds (including signal_wait_time); max_wait_time_ms; and signal_wait_time, which is the difference between the time the waiting thread was signaled and when it started running.&quot;

To:

&quot;The DMV sys.dm_os_wait_stats contains the following attributes: wait_type; waiting_tasks_count, which is the number of waits on this wait type; wait_time_ms, which is total wait time for this wait type in milliseconds (including signal_wait_time); max_wait_time_ms; and signal_wait_time_ms, which is the difference between the time the waiting thread was signaled and when it started running.&quot;

Page 81: Missing spaces in Table 3-3
On page 81, the items in the &quot;counter_name&quot; column read:

&quot;Buffercachehitratio

Buffer cache hit ratio base

Pagelookups/sec

Freeliststalls/sec

Freepages

Totalpages

Targetpages

Databasepages

Reservedpages

Stolenpages&quot;

They should read:

&quot;Buffer cache hit ratio

Buffer cache hit ratio base

Page lookups/sec

Free list stalls/sec

Free pages

Total pages

Target pages

Database pages

Reserved pages

Stolen pages&quot;

Page 101: &quot;1000&quot; used in place of &quot;1000000&quot;
On page 101, the second and fourth line in the sample code reads:

CAST(AQ1.total_duration / 1000.

CAST(SUM(AQ2.total_duration) / 1000.

It should read:

CAST(AQ1.total_duration / 100000.

CAST(SUM(AQ2.total_duration) / 100000.

Pages 102, 103: &quot;1000&quot; used in place of &quot;1000000&quot;
On pages 102 and 103, the 4th and 6th line of the code samples reads:

CAST(AQ1.total_duration / 1000.

CAST(SUM(AQ2.total_duration) / 1000.

It should read:

CAST(AQ1.total_duration / 100000.

CAST(SUM(AQ2.total_duration) / 100000.

Page 137: Ordered scan referenced rather than unordered scan
On page 137, the third sentence on the page reads:

&quot;With no fragmentation at all, the performance of an ordered scan of an index should be very close to the performance of an ordered scan, because both will end up reading the data physically in a sequential manner.&quot;

It should read:

&quot;With no fragmentation at all, the performance of an ordered scan of an index should be very close to the performance of an unordered scan, because both will end up reading the data physically in a sequential manner.&quot;

Page 139: &quot;not used&quot; should be &quot;used not&quot;
On page 139, the first sentence on the page the words &quot;not used&quot; are out of sequence.

Change:

&quot;An ordered index scan is not used only when you explicitly request the data sorted; rather, it is also used when the plan uses an operator that can benefit from sorted input data.&quot;

To:

&quot;An ordered index scan is used not only when you explicitly request the data sorted; rather, it is also used when the plan uses an operator that can benefit from sorted input data.&quot;

Page 140: The orderid should be 120 in the sixth sentence of the paragraph following the query
On page 140, in the paragraph following the query, sentence 6 reads:

&quot;The second part of the access method is an ordered partial scan in the leaf level from the first key in the range until the last (orderid = 101).&quot;

It should read:

&quot;The second part of the access method is an ordered partial scan in the leaf level from the first key in the range until the last (orderid = 120).&quot;

Page 141: Index Scan referenced in place of Index Seek
On page 141, the first sentence of the last paragraph reads:

&quot;Note that in the execution plan you won’t explicitly see the partial scan part of the access method; rather, it’s hidden in the Index Scan operator.&quot;

It should read:

&quot;Note that in the execution plan you won’t explicitly see the partial scan part of the access method; rather, it’s hidden in the Index Seek operator.&quot;

Page 158: The term &quot;grows larger&quot; is used instead of the term &quot;gets lower&quot;
On page 158, the second sentence of the paragraph after figure 3-49 reads:

&quot;As the selectivity of the query grows larger, the more substantial the cost is of the lookups here.&quot;

It should read:

&quot;As the selectivity of the query gets lower (low selectivity = high percentage of rows), the more substantial the cost is of the lookups here.&quot;

Page 162: The third line from the top needs UNIQUE removed and orderdate replacing orderid
On page 162, the 3rd line from the top reads:

&quot;CREATE UNIQUE CLUSTERED INDEX idx_cl_od ON dbo.Orders(orderid);&quot;

It should read:

&quot;CREATE CLUSTERED INDEX idx_cl_od ON dbo.Orders(orderdate);&quot;

Pages 163-166: Unordered Nonclustered Index Scan referred to as Unordered Covering Nonclustered Index Scan
On page 163, the first cell in the second and third rows of Table 3-16 read:

&quot;Unordered Covering Nonclustered Index Scan

Unordered Covering Nonclustered Index Scan + Lookups&quot;

They should read:

&quot;Unordered Nonclustered Index Scan

Unordered Nonclustered Index Scan + Lookups&quot;

On page 164, the second and third items on the left-hand side of the key for Figure 3-55 read:

&quot;Unordered Covering Nonclustered Index Scan

Unordered Covering Nonclustered Index Scan + Lookups&quot;

They should read:

&quot;Unordered Nonclustered Index Scan

Unordered Nonclustered Index Scan + Lookups&quot;

On page 164, the first cell in the second and third rows of Table 3-17 read:

&quot;Unordered Covering Nonclustered Index Scan

Unordered Covering Nonclustered Index Scan + Lookups&quot;

They should read:

&quot;Unordered Nonclustered Index Scan

Unordered Nonclustered Index Scan + Lookups&quot;

On page 165, the second and third items on the left-hand side of the key for Figure 3-56 read:

&quot;Unordered Covering Nonclustered Index Scan

Unordered Covering Nonclustered Index Scan + Lookups&quot;

They should read:

&quot;Unordered Nonclustered Index Scan

Unordered Nonclustered Index Scan + Lookups&quot;

On page 166, the labels for the second and third columns in Figure 3-57 read:

&quot;Unordered Covering Nonclustered Index Scan

Unordered Covering Nonclustered Index Scan + Lookups&quot;

They should read:

&quot;Unordered Nonclustered Index Scan

Unordered Nonclustered Index Scan + Lookups&quot;

Page 168: &quot;scan fragmentation&quot; should be &quot;page density&quot;
On page 168, the third sentence of the second paragraph contains an incorrect reference to &quot;scan fragmentation&quot;.

Change:

&quot;While logical scan fragmentation is never a good thing, average scan fragmentation has two facets.&quot;

To:

&quot;While logical scan fragmentation is never a good thing, average page density has two facets.&quot;

Page 173: Customer information referenced rather than session information
On page 173, the second sentence in the second paragraph reads:

&quot;Ideally, you should be thinking about the number of customers, the number of different order dates, and so on.&quot;

It should read:

&quot;Ideally, you should be thinking about realistic distribution of session start times, session duration, and so on.&quot;

Page 173: Listing 3-7 table name should be BigSessions instead of sessions
On page 173, the caption of Listing 3-7 reads:

&quot;Populate sessions with inadequate sample data&quot;

It should read:

&quot;Populate BigSessions with inadequate sample data&quot;

Page 187: &quot;yes&quot; should be &quot;no&quot;
On page 187, the third sentence after Figure 3-66 contains an incorrect word.

Change:

&quot;If the answer is yes, another seek operation is invoked against the index to check whether an order exists at all.&quot;

To:

&quot;If the answer is no, another seek operation is invoked against the index to check whether an order exists at all.&quot;

Page 192: Correction in fourth paragraph subquery example instructions
On page 192, the fourth paragraph subquery example instructions reads:

&quot;For example, run the following code three times: once as shown, a second time with LIKE N’Kollar’ in place of LIKE N’Davolio’, and a third time with LIKE N'D%:&quot;

It should read:

&quot;For example, run the following code three times: once as shown, a second time with LIKE N’Kollar’ in place of LIKE N’Davolio’, and a third time with LIKE N'D%':&quot;

Page 203: Variable b referenced in place of variable c
On page 203, the third sentence on the page reads:

&quot;The predicate b NOT IN(a, b, NULL) therefore returns NOT UNKNOWN, which equals UNKNOWN, and customer c is not returned by the query, either, even though c does not appear in the customer list.&quot;

It should read:

&quot;The predicate c NOT IN(a, b, NULL) therefore returns NOT UNKNOWN, which equals UNKNOWN, and customer c is not returned by the query, either, even though c does not appear in the customer list.&quot;

Page 203: &quot;EXISTS&quot; should be &quot;NOT EXISTS&quot;
On page 203, the last sentence of the first paragraph contains an incorrect query.

Change:

&quot;To make the NOT IN query logically equivalent to the EXISTS query, declare the column as NOT NULL (if appropriate) or add a filter to the subquery to exclude NULLs:&quot;

To:

&quot;To make the NOT IN query logically equivalent to the NOT EXISTS query, declare the column as NOT NULL (if appropriate) or add a filter to the subquery to exclude NULLs:&quot;

Page 206: &quot;MIN(keycol) + 1&quot; should be &quot;MIN(keycol + 1)&quot;
On page 206, the third sentence in the second paragraph contains an incorrect expression.

Change:

&quot;If 1 doesn’t exist in the table (that is, the second EXISTS predicate is always FALSE), the filter generates an empty set and the expression MIN(keycol) + 1 yields a NULL.&quot;

To:

&quot;If 1 doesn’t exist in the table (that is, the second EXISTS predicate is always FALSE), the filter generates an empty set and the expression MIN(keycol + 1) yields a NULL.&quot;

Page 272: &quot;ranking functions&quot; and &quot;recursive queries&quot; referred to rather than &quot;PIVOT&quot; and &quot;UNPIVOT&quot;
On page 272, the first sentence of the Note at the bottom of the page reads:

&quot;Changing the compatibility mode of a database to an earlier version will prevent you from using the new language elements (for example, ranking functions, recursive queries, and so on).&quot;

It should read:

&quot;Changing the compatibility mode of a database to an earlier version will prevent you from using the new language elements (for example, PIVOT, UNPIVOT, and so on).&quot;

Page 328: &quot;running&quot; should be &quot;sliding&quot;
On page 328, the first sentence after the Note box contains an incorrect aggregate.

Change:

&quot;The main difference between the solution for cumulative aggregates and the solution for running aggregates is in the join condition (or in the subquery’s filter, in the case of the alternate solution using subqueries).&quot;

To:

&quot;The main difference between the solution for cumulative aggregates and the solution for sliding aggregates is in the join condition (or in the subquery’s filter, in the case of the alternate solution using subqueries).&quot;

Page 340: Yearly Quantities refered to rather than Yearly Orders in the caption for Table 6-16
On page 340, the caption for Table 6-16 reads:

&quot;Count of Yearly Quantities per Customer&quot;

It should read:

&quot;Count of Yearly Orders per Customer&quot;

Page 356: period missing from attribute
On page 356, the fifth line in Step 15 contains an attribute that is missing a period.

Change:

&quot;Native serialization requires that the StructLayoutAttribute be specified as StructLayout.LayoutKindSequential if the UDA is defined in a class and not a structure.&quot;

To:

&quot;Native serialization requires that the StructLayoutAttribute be specified as StructLayout.LayoutKind.Sequential if the UDA is defined in a class and not a structure.&quot;

Page 364: Incorrect labels for the second and third columns of Table 6-24
On page 364, the column labels for Table 6-24:

&quot;groupid agg_or agg_or_binval&quot;

They should read:

&quot;groupid agg_and agg_and_binval&quot;

Page 364: Incorrect labels for the second and third columns of Table 6-25
On page 364, the column labels for Table 6-25 read:

&quot;groupid agg_or agg_or_binval&quot;

They should read:

&quot;groupid agg_xor agg_xor_binval&quot;

Page 412: &quot;2147483648&quot; should be &quot;-2147483648&quot;
On page 412, the first sentence of the second to last paragraph contains an incorrect integer.

Change:

&quot;CHECKSUM returns an integer between 2147483648 and 2147483647.&quot;

To:

&quot;CHECKSUM returns an integer between -2147483648 and 2147483647.&quot;

Pages 431 and 432: #CustStage referred to rather than #CustsStage
On page 431, the seventh and eigth sentences of the final paragraph read:

&quot;The UPDATE makes a single pass over the rows in #CustStage. With every row that the UPDATE visits, it stores the value of @key + 1 in KeyCol and in @key. This means that with every new row visited, @key is incremented by one and stored in KeyCol. You basically distribute the new block of sequence values among the rows in #CustStage.&quot;

They should read:

&quot;The UPDATE makes a single pass over the rows in #CustsStage. With every row that the UPDATE visits, it stores the value of @key + 1 in KeyCol and in @key. This means that with every new row visited, @key is incremented by one and stored in KeyCol. You basically distribute the new block of sequence values among the rows in #CustsStage.&quot;

On page 432, the first sentence on the page reads:

&quot;this code after resetting the sequence value to 0, as instructed earlier, #CustStage will contain seven UK customers, with KeyCol values ranging from 1 through 7.&quot;

It should read:

&quot;this code after resetting the sequence value to 0, as instructed earlier, #CustsStage will contain seven UK customers, with KeyCol values ranging from 1 through 7.&quot;

On page 432, the first sentence of the second paragraph reads:

&quot;The specialized T-SQL UPDATE statement is not standard and doesn’t guarantee it will access the rows in #CustStage in any particular order.&quot;

It should read:

&quot;The specialized T-SQL UPDATE statement is not standard and doesn’t guarantee it will access the rows in #CustsStage in any particular order.&quot;

Page 434: usp_AsyncSec refered to rather than usp_AsyncSeq
On page 434, the second sentence after the Note box reads:

&quot;The rollback prevents the AsyncSeq table from growing. In fact, it will never contain any rows from calls to usp_AsyncSec.&quot;

It should read:

&quot;The rollback prevents the AsyncSeq table from growing. In fact, it will never contain any rows from calls to usp_AsyncSeq.&quot;

Page 445: Incorrect SET statement in the first code sample
On page 445, the last two lines of the first code sample reads:

WHERE C.CustomerID = dbo.Orders.CustomerID); WHERE C.Country = 'USA';

They should read:

WHERE C.CustomerID = dbo.Orders.CustomerID); WHERE CustomerID IN (SELECT CustomerID FROM dbo.Customers WHERE Country = 'USA');

Page 445: &quot;many&quot; should be &quot;one&quot;
On page 445. the second sentence of the last paragraph contains an incorrect side reference.

Change:

&quot;When you modify the table on the “many” side of a one-to-many join, you might end up with a nondeterministic update.&quot;

To:

&quot;When you modify the table on the “one” side of a one-to-many join, you might end up with a nondeterministic update.&quot;

Page 480: fn_subordinates2 referenced in place of fn_subordinates1
On page 480, the last sentence before Listing 9-8 reads:

&quot;Run the code in Listing 9-8 to create the fn_subordinates2 function, which is a revision of fn_subordinates2 that also supports a level limit.&quot;

It should read:

&quot;Run the code in Listing 9-8 to create the fn_subordinates2 function, which is a revision of fn_subordinates1 that also supports a level limit.&quot;

Page 485: < should be <=
On page 485, in the code sample, the comment on line 12 contains an incorrect symbol.

Change: -- and previous level < @maxlevels

To: -- and previous level <= @maxlevels

Page 493: &quot;SubsPath&quot; should be &quot;SubsSort&quot;
On page 496, line 36 of the sample code on the page needs to have &quot;SubsPath&quot; replaced with &quot;SubsSort&quot;.

Change: -- #SubsPath is a temp table that will hold the final

To: -- #SubsSort is a temp table that will hold the final

Page 494: @ should be #
On page 494, in the code sample, the 4th comment above the last INSERT statement contains an incorrect symbol.

Change: -- Load the rows from #SubsPath to @SubsSort sorted by the binary

To: -- Load the rows from #SubsPath to #SubsSort sorted by the binary

Page 506: Incorrect use of apostrophe
On page 506, the fourth sentence of the second to the last paragraph on the page incorrect places an apostrophe before the word employee.

Change:

&quot;Otherwise, its level is the parent’s level plus 1, and its path is: parent path + ‘employee id + ‘.’.&quot;

To:

&quot;Otherwise, its level is the parent’s level plus 1, and its path is: parent path + employee id + ‘.’.&quot;

Page 513: Reference to Table 9-35 should be more specific
On page 513, the first two full sentences on the page read:

&quot;For each request, I’ll provide a sample query followed by its output (shown in Table 9-35). Return the subtree with a given root:&quot;

It should read:

&quot;For each request, I’ll provide a sample query followed by its output. Return the subtree with a given root, generating the output shown in Table 9-35:&quot;

Page 533: &quot;BOMCTE&quot; should be &quot;BOMTC&quot;
On page 533, the first sentence after Table 9-50 includes an incorrect acronym.

Change:

&quot;This solution eliminates duplicate edges found in the BOMCTE by applying a DISTINCT clause in the outer query.&quot;

To:

&quot;This solution eliminates duplicate edges found in the BOMTC by applying a DISTINCT clause in the outer query.&quot;

Page 562: Lamp 36 missing from the list of lamps that are on
On page 562, the first sentence of the answer to Puzzle 10 reads:

&quot;All the lamps are off except for lamps number 1, 4, 9, 16, 25, 49, 64, 81, and 100, which are on.&quot;

It should read:

&quot;All the lamps are off except for lamps number 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100, which are on.&quot;

Page 567: Corretion to Puzzle 19 answer
On page 567, under &quot;Puzzle 19: Find the pattern in the Sequence&quot;, in last sentence, the first number in the sequence - 4 - was added by mistake.

Change:

&quot;Here’s the first part of the sequence with a few additional numbers: 4, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, …&quot;

To:

&quot;Here’s the first part of the sequence with a few additional numbers: 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8, 6, 9, 9, 11, 10, 10, 9, 11, 11, 10, …&quot;

Microsoft Press is committed to providing informative and accurate books. All comments and corrections listed above are ready for inclusion in future printings of this book. If you have a later printing of this book, it may already contain most or all of the above corrections.

Additional query words: 0-7356-2313-9 978-0-7356-2313-2

Keywords: KB920141

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.