Corrections/Comments
 

Home
Books
T-SQL Courses
Resources
Blog
About BG


Inside Microsoft SQL Server 2008: T-SQL Querying

Last modified: 2011-11-28
Note: If you have a later printing of this book, it may already contain the below corrections.

Introduction
Chapter 01: Logical Query Processing
Chapter 02: Set Theory and Predicate Logic
Chapter 03: Relational Model
Chapter 04: Query Tuning
Chapter 05: Complexity and Algorithms
Chapter 06: Subqueries, Table Expressions and Ranking Functions
Chapter 07: Joins and Set Operations
Chapter 08: Aggregating and Pivoting Data
Chapter 09: TOP and APPLY
Chapter 10: Data Modification
Chapter 11: Querying Partitioned Tables
Chapter 12: Graphs, Trees, Hierarchies and Recursive Queries
Appendix A: Logic Puzzles

Index

 

Inside Microsoft SQL Server 2008: T-SQL Programming

Last modified: 2011-10-25
Note: If you have a later printing of this book, it may already contain the below corrections.

TOC
Chapter 01: Views
Chapter 02: User Defined Functions
Chapter 03: Stored Procedures
Chapter 04: Triggers
Chapter 05: Transactions and Concurrency
Chapter 06: Error Handling
Chapter 07: Temporary Tables and Table Variables
Chapter 08: Cursors
Chapter 09: Dynamic SQL
Chapter 10: Working with Date and Time
Chapter 11: CLR User Defined Types
Chapter 12: Temporal Support in the Relational Model
Chapter 13: XML and XQuery
Chapter 14: Spatial Data
Chapter 15: Tracking Access and Changes to Data
Chapter 16: Service Broker
Appendix A - Companion to CLR Routines

 

Inside Microsoft SQL Server 2008: T-SQL Querying

Introduction

Date / By Where Correction
2009-05-26 /
Itzik Ben-Gan
Page xxii, Last paragraph, First sentence Currently: "After downloading the source code, run the script file TSQLFundamentals2008.sql"

Should be: "After downloading the source code, run the script file InsideTSQL2008.sql"
2009-05-26 /
Itzik Ben-Gan
Page xxiii, Caption of Figure I-1 Currently: "Data model of the TSQLFundamentals2008 database"

Should be: "Data model of the InsideTSQL2008 database.sql"

Chapter 01

Date / By Where Correction
2009-07-10 /
Valentino Vranken
Chapter 1, Page 18, Query output at bottom of page Currently:

orderid     customerid
----------- ----------
11077       RATTC
11076       BONAP
11075       RICSU

Should be:

orderid     customerid
----------- ----------
7           NULL
6           MRPHS
5           KRLOS
2009-11-09 /
Gunnar Nyberg
Chapter 1, Page 32, Output of first query Currently:

country         region          city
--------------- --------------- ---------------
USA             WA              Kirkland
USA             WA              Seattle

Should be:

region          city
--------------- ---------------
WA              Kirkland
WA              Seattle

Chapter 02

Chapter 03

Date / By Where Correction
2010-01-18 / Brad Pool Chapter 3, Tables 3-1..17 Currently: A couple of places in the chapter (page 113, sentence before Table 3-1, page 117, last sentence) refer to shaded columns in the tables representing primary keys. The shading was part of the original tables but didn't make it to print.

Should be: following are the tables with the shading of the primary key columns:

Table 3-1 A Table Before 1NF

OrderId

CustomerId

CustomerName

OrderDate

Items

1

1

Company ABC

2008-10-22

Ap Apples q=5, Ch Cherries q=10

2

1

Company ABC

2008-10-24

Ba Bananas q=12

3

2

Company ABC

2008-09-15

Ap Apples q=3, Ba Bananas q=3

Table 3-2 A Table in 1NF

OrderId

CustomerId

CustomerName

OrderDate

ItemID

ProductId

Quantity

ProductName

1

1

Company ABC

2008-10-22

1

Ap

5

Apples

1

1

Company ABC

2008-10-22

2

Ch

10

Cherries

2

1

Company ABC

2008-10-24

1

Ba

12

Bananas

3

2

XYZ

2008-09-15

1

Ap

3

Apples

3

2

XYZ

2008-09-15

2

Ba

3

Bananas

Table 3-3 The Orders Table in 2NF

OrderId

CustomerId

CustomerName

OrderDate

1

1

Company ABC

2008-10-22

2

1

Company ABC

2008-10-24

3

2

XYZ

2008-09-15

Table 3-4 The OrderDetails Table in 2NF

OrderId

ItemId

ProductId

Quantity

ProductName

1

1

Ap

5

Apples

1

2

Ch

10

Cherries

2

1

Ba

12

Bananas

3

1

Ap

3

Apples

3

2

Ba

3

Bananas

Table 3-5 The Customers Table in 3NF

CustomerId

CustomerName

1

Company ABC

2

XYZ

Table 3-6 The Orders Table in 3NF

OrderId

CustomerId

OrderDate

1

1

2008-10-22

2

1

2008-10-24

3

2

2008-09-15

Table 3-7 The OrderDetails Table in 3NF

OrderId

ItemId

ProductId

Quantity

1

1

Ap

5

1

2

Ch

10

2

1

Ba

12

3

1

Ap

3

3

2

Ba

3

Table 3-8 The Products Table in 3NF

ProductId

ProductName

Ap

Apples

Ch

Cherries

Ba

Bananas

Table 3-9 The Imaginary Orders Table

CustomerId

OrderDate

DueDate

OtherOrderColumns

1

2008-10-22

2008-10-23

1

2008-10-24

2008-10-25

2

2008-09-15

2008-09-16

Table 3-10 The Orders Table in BCNF: First Solution

CustomerId

OrderDate

StandardShippingTimeDays

OtherOrderColumns

1

2008-10-22

1

1

2008-10-24

1

2

2008-09-15

1

Table 3-11 The Orders Table in BCNF: Second Solution

OrderId

CustomerId

OrderDate

DueDate

OtherOrderColumns

1

1

2008-10-22

2008-10-23

2

1

2008-10-24

2008-10-25

3

2

2008-09-15

2008-09-16

Table 3-12 The Employees-Projects-Activities Table

Employee

Project

Activity

1

Proj 111

ABC

1

Proj 111

DEF

1

Proj 222

ABC

1

Proj 222

DEF

2

Proj 111

ABC

2

Proj 111

XYZ

Table 3-13 The Employees-Projects-Activities Table with Multivalued Columns

Employee

Project

Activity

1

 

Proj 111

Proj 222

ABC

DEF

2

 

Proj 111

 

ABC

XYZ

Table 3-14 The Employees-Projects Table

Employee

Project

1

Proj 111

1

Proj 222

2

Proj 111

Table 3-15 The Employees-Activities Table

Employee

Activity

1

ABC

1

DEF

2

ABC

2

XYZ

Table 3-16 The Employees-Projects-Activities Table

Employee

Project

Activity

1

Proj 111

ABC

1

Proj 111

DEF

1

Proj 222

ABC

2

Proj 111

ABC

2

Proj 111

XYZ

Table 3-17 The Projects-Activities Table

Project

Activity

Proj 111

ABC

Proj 111

DEF

Proj 222

ABC

Proj 111

XYZ

 

Chapter 04

Date / By Where Correction
2011-11-28 /
Dima Piliugin
Page 190, Figure 4-15

Currently: There's a pointer to first 1:47120 that shouldn't be there.

Should be: Mistaken pointer should be removed.

2010-07-14 /
Balog Gergely
Page 249, Fourth sentence from bottom of page Currently: "Don’t forget that page reads are the only factor that you should take into consideration."

Should be: "Don’t forget that page reads are not the only factor that you should take into consideration."

Chapter 05

Chapter 06

Date / By Where Correction
2009-11-15 /
Robert Forrest
Page 318, syntax for derived tables above Note Currently: FROM (derived_table_query) AS derived_table_alias

Should be: FROM (<derived_table_query>) AS <derived_table_alias>
2009-11-15 /
Robert Forrest
Page 322, definition of CTE after first paragraph Currently:

WITH cte_name
AS
(
  cte_query
)
outer_query_referring_to_cte_name

Should be:

WITH <cte_name>[( <target_column_list> )]
AS
(
  <inner_query_defining_cte>
)
<outer_query_against_cte>;

2009-11-03 /
Robert Forrest
Page 331, Middle of page Currently: ranking_function OVER([PARTITION BY col_list] ORDER BY col_list)

Should be: <ranking_function> OVER([PARTITION BY <col_list>] ORDER BY <col_list>)

2010-10-07 /
Shengying Hou
Page 339, Second column heading in output of query at bottom of page Currently: dups

Should be: cnt

Chapter 07

Date / By Where Correction
2009-11-03 /
Robert Forrest
Page 389, Last line on page Currently: WHERE where_predicate

Should be: WHERE <where_predicate>

2009-11-03 /
Robert Forrest
Page 390, Line 7 Currently: WHERE where_predicate

Should be: WHERE <where_predicate>

2010-07-01 /
Joe'l Satterfield
Page 438, Query in body of page Currently:
WITH EXCEPT_ALL
AS
(
  SELECT
    ROW_NUMBER() 
      OVER(PARTITION BY country, region, city
           ORDER     BY (SELECT 0) AS rn,
    country, region, city
    FROM HR.Employees

  EXCEPT

  SELECT
    ROW_NUMBER() 
      OVER(PARTITION BY country, region, city
           ORDER     BY (SELECT 0) AS rn,
    country, region, city
  FROM Sales.Customers
)
SELECT country, region, city
FROM EXCEPT_ALL;

Error: missing closing parenthesis after (SELECT 0) in both ROW_NUMBER expressions.

Should be:

WITH EXCEPT_ALL
AS
(
  SELECT
    ROW_NUMBER() 
      OVER(PARTITION BY country, region, city
           ORDER     BY (SELECT 0)) AS rn,
    country, region, city
    FROM HR.Employees

  EXCEPT

  SELECT
    ROW_NUMBER() 
      OVER(PARTITION BY country, region, city
           ORDER     BY (SELECT 0)) AS rn,
    country, region, city
  FROM Sales.Customers
)
SELECT country, region, city
FROM EXCEPT_ALL;

Chapter 08

Date / By Where Correction
2010-10-18 /
Shengying Hou
Chapter 8, Page 472, Output of first query in page Correction: Output of query should not include the last two rows with the zero quantities.
2009-09-15 /
Tóth Rudolf, Adam Machanic
Chapter 8, Page 490, First (and only) query in page Currently:

SELECT groupid,
  CAST(ROUND(EXP(SUM(LOG(ABS(NULLIF(val,0)))))*
    (1-SUM(1-SIGN(val))%4)*(1-SUM(1-SQUARE(SIGN(val)))),0) AS INT)
  AS product
FROM dbo.Groups
GROUP BY groupid;


Should be:

SELECT groupid,
  COALESCE(CAST(ROUND(EXP(SUM(LOG(ABS(NULLIF(val,0)))))*
    (1-SUM(1-SIGN(val))%4)*MIN(ABS(SIGN(val))),0) AS INT), MAX(val))
  AS product
FROM dbo.Groups
GROUP BY groupid;

Chapter 09

Chapter 10

Date / By Where Correction

2010-01-12 /
Erland Sommarskog, Plamen Ratchev

Page 605, Fifth line Currently: T-SQL doesn’t support qualifying a column name with a table variable name.

Correction: T-SQL does support qualifying a column with a table variable name provided that you delimit it, e.g., [@MyOD].orderid.

Chapter 11

Chapter 12

Appendix A

Index

Date / By Where Correction
2009-10-10 /
Robert Forrest
Page 790, Under OVER clause Error: subclauses is misspelled as "subcaluses"

 

Inside Microsoft SQL Server 2008: T-SQL Programming

TOC

Date / By Where Correction
2009-10-28
Robert Forrest
TOC, Page vii, Chapter 7's heading Currently: Temporary Tablesand Table Variables

Should be: Temporary Tables and Table Variables

Chapter 01

Date / By Where Correction
2009-10-24
Robert Forrest
Chapter 1, Page 17, First bullet point Currently: You cannot insert data through a view if the view doesn’t include even one column from the underlying table that doesn’t get its value implicitly. A column can get a value implicitly if it allows NULLs, has a default value, has an IDENTITY property, or is typed as ROWVERSION.

Problem: Confusing as written.

Should be: INSERT statements must specify values for any columns in the underlying table that do not have implicit values. A column can get a value implicitly if it allows NULLS, has a default value, has an IDENTITY property, or is typed as ROWVERSION.

Chapter 02

Date / By Where Correction
2009-10-28
Robert Forrest
Chapter 3, Page 117, Third line Currently: <query> OPTION(OPTIMIZER FOR(@p1 UNKNOWN, @p2 UNKNWON, ...);

Should be: <query> OPTION(OPTIMIZE FOR(@p1 UNKNOWN, @p2 UNKNOWN, ...);

2009-10-28
Robert Forrest
Chapter 3, Page 117, Sixth line Currently: <query> OPTION(OPTIMIZER FOR UNKNWON);

Should be: <query> OPTION(OPTIMIZE FOR UNKNOWN);

Chapter 03

Date / By Where Correction
2009-10-28
Robert Forrest
Chapter 5, Page 154, Third paragraph from bottom of page Currently: For encapsulation purposes, I’ll create three stored procedures: one that sets the signal, one that clears it, and one that returns it. Eventually I didn't create them as special procedures.

Problem: Last statement is an editorial comment and made it to the text by mistake. The statement should be ignored.

Should be: For encapsulation purposes, I’ll create three stored procedures: one that sets the signal, one that clears it, and one that returns it.

Chapter 04

Chapter 05

Chapter 06

Date / By Where Correction
2011-10-25
Martin Smith
Chapter 6, Page 226, First sentence below third code sample Currently: What you end up getting in @rc is the number of rows affected by the first assignment (namely 0), instead of the number of rows affected by the suspect statement.

Should be: What you end up getting in @rc is the number of rows affected by the first assignment (namely 1), instead of the number of rows affected by the suspect statement.

Chapter 07

Chapter 08

Chapter 09

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Chapter 15

Chapter 16

Appendix A

 

Back to Inside T-SQL 2008 Main Page


 

Home ] Books ] T-SQL Courses ] Resources ] Blog ] About BG ]

[SolidQ Home] [SolidQ Blog] [SolidQ Courses] [The SolidQ journal]