- Page 2 and 3:
Programmer to Programmer Get more
- Page 5:
Beginning Microsoft SQL Ser ver® 2
- Page 8 and 9:
Beginning Microsoft SQL Ser ver® 2
- Page 11:
About the Author Experiencing his f
- Page 15:
Acknowledgments Over the years, the
- Page 18 and 19:
Contents Chapter 2:T ools of the T
- Page 20 and 21:
Contents xviii The CREATE Statement
- Page 22 and 23:
Contents xx Correlated Subqueries 1
- Page 24 and 25:
Contents xxii SORT_IN_TEMPDB 280 ON
- Page 26 and 27:
Contents xxiv Control-of-Flow State
- Page 28 and 29:
Contents xxvi How the SQL Ser ver L
- Page 30 and 31:
Contents Chapter 16: A Brief XML Pr
- Page 32 and 33:
Contents Chapter 19: Pla ying Admin
- Page 34 and 35:
Introduction The beginning user wil
- Page 36 and 37:
Introduction ❏ We show file names
- Page 38 and 39:
Introduction xxxvi ❏ Understand t
- Page 40 and 41:
Chapter 1: RDBMS Basics: What Makes
- Page 42 and 43:
Chapter 1: RDBMS Basics: What Makes
- Page 44 and 45:
Chapter 1: RDBMS Basics: What Makes
- Page 46 and 47:
Chapter 1: RDBMS Basics: What Makes
- Page 48 and 49:
Chapter 1: RDBMS Basics: What Makes
- Page 50 and 51:
Chapter 1: RDBMS Basics: What Makes
- Page 52 and 53:
Chapter 1: RDBMS Basics: What Makes
- Page 54 and 55:
Chapter 1: RDBMS Basics: What Makes
- Page 56 and 57:
Chapter 1: RDBMS Basics: What Makes
- Page 58 and 59:
Chapter 1: RDBMS Basics: What Makes
- Page 60 and 61:
Chapter 2: Tools of the Trade 22 My
- Page 62 and 63:
Chapter 2: Tools of the Trade ❑ S
- Page 64 and 65:
Chapter 2: Tools of the Trade 26 Ke
- Page 66 and 67:
Chapter 2: Tools of the Trade 28 Th
- Page 68 and 69:
Chapter 2: Tools of the Trade 30 lo
- Page 70 and 71:
Chapter 2: Tools of the Trade 32 3.
- Page 72 and 73:
Chapter 2: Tools of the Trade 34 Fi
- Page 74 and 75:
Chapter 2: Tools of the Trade Figur
- Page 76 and 77:
Chapter 2: Tools of the Trade Note
- Page 78 and 79:
Chapter 2: Tools of the Trade bcp i
- Page 81 and 82:
3 The Foundation Statements of T-SQ
- Page 83 and 84:
asic SELECT statement. Fire up the
- Page 85 and 86:
Now let’s try taking a little bit
- Page 87 and 88:
very few of your tables will have s
- Page 89 and 90:
Operator Example Usage Effect ALL,
- Page 91 and 92:
Chapter 3: The Foundation Statement
- Page 93 and 94:
WHERE SalesOrderID IN (43660, 43670
- Page 95 and 96:
AVG This one is for computing avera
- Page 97 and 98:
efore, but remove the two AS keywor
- Page 99 and 100:
You’ll get a result that is a bit
- Page 101 and 102:
What if we want to place conditions
- Page 103 and 104:
Let’s say, for example, that we w
- Page 105 and 106:
Chapter 3: The Foundation Statement
- Page 107 and 108:
City varchar(20) NOT NULL, State ch
- Page 109 and 110:
for it in the INSERT statement. For
- Page 111 and 112:
And sure enough, we get back the on
- Page 113 and 114:
Chapter 3: The Foundation Statement
- Page 115 and 116:
Chapter 3: The Foundation Statement
- Page 117:
Chapter 3: The Foundation Statement
- Page 120 and 121:
Chapter 4: JOINs 82 returned is in
- Page 122 and 123:
Chapter 4: JOINs 84 Using an INNER
- Page 124 and 125:
Chapter 4: JOINs 86 Uh, oh — this
- Page 126 and 127:
Chapter 4: JOINs How It Works Unlik
- Page 128 and 129:
Chapter 4: JOINs If we were to look
- Page 130 and 131:
Chapter 4: JOINs 92 What I’m tryi
- Page 132 and 133:
Chapter 4: JOINs 16 Mountain-500 Si
- Page 134 and 135:
Chapter 4: JOINs 96 Let’s use thi
- Page 136 and 137:
Chapter 4: JOINs 98 vendor. We’re
- Page 138 and 139:
Chapter 4: JOINs 100 Somehow, we lo
- Page 140 and 141:
Chapter 4: JOINs Try It Out FULL JO
- Page 142 and 143:
Chapter 4: JOINs Every time I teach
- Page 144 and 145:
Chapter 4: JOINs JOIN Sales.Special
- Page 146 and 147:
Chapter 4: JOINs Figure 4-1 As alwa
- Page 148 and 149:
Chapter 4: JOINs 110 CREATE TABLE U
- Page 150 and 151:
Chapter 4: JOINs There are two diff
- Page 152 and 153:
Chapter 5: Creating and Altering Ta
- Page 154 and 155:
Chapter 5: Creating and Altering Ta
- Page 156 and 157:
Chapter 5: Creating and Altering Ta
- Page 158 and 159:
Chapter 5: Creating and Altering Ta
- Page 160 and 161:
Chapter 5: Creating and Altering Ta
- Page 162 and 163:
Chapter 5: Creating and Altering Ta
- Page 164 and 165:
Chapter 5: Creating and Altering Ta
- Page 166 and 167:
Chapter 5: Creating and Altering Ta
- Page 168 and 169:
Chapter 5: Creating and Altering Ta
- Page 170 and 171:
Chapter 5: Creating and Altering Ta
- Page 172 and 173:
Chapter 5: Creating and Altering Ta
- Page 174 and 175:
Chapter 5: Creating and Altering Ta
- Page 176 and 177:
Chapter 5: Creating and Altering Ta
- Page 178 and 179:
Chapter 5: Creating and Altering Ta
- Page 180 and 181:
Chapter 5: Creating and Altering Ta
- Page 182 and 183:
Chapter 5: Creating and Altering Ta
- Page 184 and 185:
Chapter 5: Creating and Altering Ta
- Page 186 and 187:
Chapter 5: Creating and Altering Ta
- Page 188 and 189:
Chapter 5: Creating and Altering Ta
- Page 190 and 191:
Chapter 5: Creating and Altering Ta
- Page 192 and 193:
Chapter 6: Constraints At a more sp
- Page 194 and 195:
Chapter 6: Constraints We can then
- Page 196 and 197:
Chapter 6: Constraints A table can
- Page 198 and 199:
Chapter 6: Constraints FOREIGN KEY
- Page 200 and 201:
Chapter 6: Constraints How It Works
- Page 202 and 203:
Chapter 6: Constraints Cascading Ac
- Page 204 and 205:
Chapter 6: Constraints 166 This is
- Page 206 and 207:
Chapter 6: Constraints 168 FROM Ord
- Page 208 and 209:
Chapter 6: Constraints 170 Let’s
- Page 210 and 211:
Chapter 6: Constraints CHECK Constr
- Page 212 and 213:
Chapter 6: Constraints Defining a D
- Page 214 and 215:
Chapter 6: Constraints Ignoring Bad
- Page 216 and 217:
Chapter 6: Constraints Try running
- Page 218 and 219:
Chapter 6: Constraints Rules and De
- Page 220 and 221:
Chapter 6: Constraints Dropping Rul
- Page 222 and 223:
Chapter 6: Constraints 184 Restrict
- Page 225 and 226:
7 Adding More to Our Queries When I
- Page 227 and 228:
Building a Nested Subquery A nested
- Page 229 and 230:
While this works just fine, queries
- Page 231 and 232:
We’ll go back to the AdventureWor
- Page 233 and 234:
❑ Aliases are used in both querie
- Page 235 and 236:
Now let’s see this at work in our
- Page 237 and 238:
So let’s take this now and apply
- Page 239 and 240:
This join-based syntax, for example
- Page 241 and 242:
IF NOT EXISTS (SELECT ‘True’ FR
- Page 243 and 244:
The conversions can actually get a
- Page 245 and 246:
there are no other roll up records
- Page 247 and 248:
GROUP BY soh.OrderDate, sod.Product
- Page 249 and 250:
OUTPUT $action, inserted.Year, inse
- Page 251 and 252:
The long-standing, traditional view
- Page 253 and 254:
8 Being Normal: Normalization and O
- Page 255 and 256:
Chapter 8: Being Normal: Normalizat
- Page 257 and 258:
Chapter 8: Being Normal: Normalizat
- Page 259 and 260:
Chapter 8: Being Normal: Normalizat
- Page 261 and 262:
Chapter 8: Being Normal: Normalizat
- Page 263 and 264:
Chapter 8: Being Normal: Normalizat
- Page 265 and 266:
Chapter 8: Being Normal: Normalizat
- Page 267 and 268:
Chapter 8: Being Normal: Normalizat
- Page 269 and 270:
Chapter 8: Being Normal: Normalizat
- Page 271 and 272:
Chapter 8: Being Normal: Normalizat
- Page 273 and 274:
Chapter 8: Being Normal: Normalizat
- Page 275 and 276:
Chapter 8: Being Normal: Normalizat
- Page 277 and 278:
Chapter 8: Being Normal: Normalizat
- Page 279 and 280:
Chapter 8: Being Normal: Normalizat
- Page 281 and 282:
Chapter 8: Being Normal: Normalizat
- Page 283 and 284:
Chapter 8: Being Normal: Normalizat
- Page 285 and 286:
Chapter 8: Being Normal: Normalizat
- Page 287 and 288:
Chapter 8: Being Normal: Normalizat
- Page 289 and 290:
Chapter 8: Being Normal: Normalizat
- Page 291 and 292:
Chapter 8: Being Normal: Normalizat
- Page 293 and 294:
Chapter 8: Being Normal: Normalizat
- Page 295 and 296:
Chapter 8: Being Normal: Normalizat
- Page 297 and 298:
Chapter 8: Being Normal: Normalizat
- Page 299 and 300:
9 SQL Ser ver Storage and Index Str
- Page 301 and 302:
Page Splits When a page becomes ful
- Page 303 and 304:
The point here is that what happens
- Page 305 and 306:
Page Splits — A First Look All of
- Page 307 and 308:
You may hear lots of bad things abo
- Page 309 and 310:
Navigating the Tree Figure 9-4 As I
- Page 311 and 312:
there was no link between the data.
- Page 313 and 314:
Root Non-Leaf Level Leaf Level Figu
- Page 315 and 316:
The CREATE INDEX Statement The CREA
- Page 317 and 318:
FILLFACTOR When SQL Server first cr
- Page 319 and 320:
works only if tempdb is on a separa
- Page 321 and 322:
Secondary XML Indexes Chapter 9: SQ
- Page 323 and 324:
occur, and that one or more non-lea
- Page 325 and 326:
isn’t room on the page, SQL Serve
- Page 327 and 328:
more administrator oriented and usu
- Page 329 and 330:
The Database Engine Tuning Advisor
- Page 331 and 332:
The output is far more self-describ
- Page 333 and 334:
We use a FILLFACTOR when we need to
- Page 335:
Chapter 9: SQL Server Storage and I
- Page 338 and 339:
Chapter 10: Views The preceding syn
- Page 340 and 341:
Chapter 10: Views 302 columns to a
- Page 342 and 343:
Chapter 10: Views Try It Out Using
- Page 344 and 345:
Chapter 10: Views 306 soh.SalesOrde
- Page 346 and 347:
Chapter 10: Views AW00000676 43659
- Page 348 and 349:
Chapter 10: Views NULL values will
- Page 350 and 351:
Chapter 10: Views Editing V iews wi
- Page 352 and 353:
Chapter 10: Views 314 There are fou
- Page 354 and 355: Chapter 10: Views Editing Views in
- Page 356 and 357: Chapter 10: Views 318 In addition,
- Page 358 and 359: Chapter 10: Views 320 from the firs
- Page 360 and 361: Chapter 10: Views You can get the y
- Page 363 and 364: 11 Writing Scripts and Batches Whet
- Page 365 and 366: Next we have a DECLARE statement to
- Page 367 and 368: I’m not going to pick any bones a
- Page 369 and 370: Using @@IDENTITY @@IDENTITY is one
- Page 371 and 372: How It Works What we’re doing in
- Page 373 and 374: DECLARE @RowCount int; --Notice the
- Page 375 and 376: When the editing tool encounters a
- Page 377 and 378: When you think about it, this seems
- Page 379 and 380: So, let’s try a quick query direc
- Page 381 and 382: We now have our text file source fo
- Page 383 and 384: Let’s build an example in the Adv
- Page 385 and 386: DECLARE @InVar varchar(50); DECLARE
- Page 387 and 388: -- This won’t work DECLARE @Numbe
- Page 389 and 390: -- Now we’re run our conditional
- Page 391 and 392: Out of the condition from inner con
- Page 393 and 394: A Simple CASE A simple CASE takes a
- Page 395 and 396: 3 8 More Than One Apart 2 2 Ends Wi
- Page 397 and 398: Now, I don’t know about you, but
- Page 399 and 400: The WAITFOR statement does exactly
- Page 401 and 402: IF @ErrorNo = 2714 -- Object exists
- Page 403: Chapter 11: Writing Scripts and Bat
- Page 407 and 408: Now that we have our sproc created,
- Page 409 and 410: The default is the first place we s
- Page 411 and 412: If we were to run this with the sam
- Page 413 and 414: ELSE -- hmm, we don’t recognize i
- Page 415 and 416: CREATE PROC spTestReturns AS DECLAR
- Page 417 and 418: Now, here things get a bit sticky a
- Page 419 and 420: SELECT @Error = @@ERROR; -- Print o
- Page 421 and 422: Our insert happens correctly, so no
- Page 423 and 424: HireDate = @HireDate, CurrentFlag =
- Page 425 and 426: Note the removal of the HireDate co
- Page 427 and 428: Go ahead and run this once: DECLARE
- Page 429 and 430: catastrophic (20-25). If you raise
- Page 431 and 432: Let’s use this in a simple exampl
- Page 433 and 434: As an example, let’s assume that
- Page 435 and 436: Figure 12-1 Time of Creation At Exe
- Page 437 and 438: If we create our sproc with this op
- Page 439 and 440: You can test the arithmetic overflo
- Page 441 and 442: ❑ There are icons at the top (see
- Page 443 and 444: The Call Stack Window The Call Stac
- Page 445 and 446: line is different. This new green a
- Page 447: Summary Wow! That’s a lot to have
- Page 450 and 451: Chapter 13: User-Defined Functions
- Page 452 and 453: Chapter 13: User-Defined Functions
- Page 454 and 455:
Chapter 13: User-Defined Functions
- Page 456 and 457:
Chapter 13: User-Defined Functions
- Page 458 and 459:
Chapter 13: User-Defined Functions
- Page 460 and 461:
Chapter 13: User-Defined Functions
- Page 462 and 463:
Chapter 13: User-Defined Functions
- Page 464 and 465:
Chapter 13: User-Defined Functions
- Page 466 and 467:
Chapter 14: Transactions and Locks
- Page 468 and 469:
Chapter 14: Transactions and Locks
- Page 470 and 471:
Chapter 14: Transactions and Locks
- Page 472 and 473:
Chapter 14: Transactions and Locks
- Page 474 and 475:
Chapter 14: Transactions and Locks
- Page 476 and 477:
Chapter 14: Transactions and Locks
- Page 478 and 479:
Chapter 14: Transactions and Locks
- Page 480 and 481:
Chapter 14: Transactions and Locks
- Page 482 and 483:
Chapter 14: Transactions and Locks
- Page 484 and 485:
Chapter 14: Transactions and Locks
- Page 486 and 487:
Chapter 14: Transactions and Locks
- Page 489 and 490:
15 Triggers Ah, triggers. Triggers
- Page 491 and 492:
ON While triggers take no parameter
- Page 493 and 494:
Statement issued: “INSERT INTO...
- Page 495 and 496:
SQL Server 6.5 and prior did not al
- Page 497 and 498:
Let’s go ahead and test out our h
- Page 499 and 500:
I just picked out “Adjustable Rac
- Page 501 and 502:
happen the second time around. Recu
- Page 503 and 504:
The syntax of sp_settriggerorder lo
- Page 505 and 506:
Another upshot of this part-of-the-
- Page 507 and 508:
5, and 7, then you need to add the
- Page 509 and 510:
that exercises the trigger we most
- Page 511 and 512:
16 A Brief XML Primer So, here we a
- Page 513 and 514:
So, this might have you asking the
- Page 515 and 516:
The declaration is made with a spec
- Page 517 and 518:
the scope of any particular XML doc
- Page 519 and 520:
As a side note, you can perform a r
- Page 521 and 522:
If we have more than one customer,
- Page 523 and 524:
The sql data type
- Page 525 and 526:
XML functionality was a relatively
- Page 527 and 528:
This is just a little confusing, so
- Page 529 and 530:
Chapter 16: A Brief XML Primer
- Page 531 and 532:
The result is rather verbose, so I
- Page 533 and 534:
If, for example, we wanted to incre
- Page 535 and 536:
7 30 1.00 7 45 0.50 7 50 3.00 7 60
- Page 537 and 538:
FOR XML provides three different in
- Page 539 and 540:
Easy, right? Well, now the boss com
- Page 541 and 542:
The downside to using AUTO is that
- Page 543 and 544:
While EXPLICIT has not been depreca
- Page 545 and 546:
Notice that our order count remaine
- Page 547 and 548:
FROM Sales.SalesOrderHeader Orders
- Page 549 and 550:
Next up are the mapping flags. Thes
- Page 551 and 552:
Imagine that you are merging with a
- Page 553 and 554:
What we have here is something XML
- Page 555 and 556:
17 Reporting for Duty , Sir! A Look
- Page 557 and 558:
Chapter 17: Reporting for Duty, Sir
- Page 559 and 560:
Chapter 17: Reporting for Duty, Sir
- Page 561 and 562:
Chapter 17: Reporting for Duty, Sir
- Page 563 and 564:
Chapter 17: Reporting for Duty, Sir
- Page 565 and 566:
Chapter 17: Reporting for Duty, Sir
- Page 567 and 568:
Chapter 17: Reporting for Duty, Sir
- Page 569 and 570:
Chapter 17: Reporting for Duty, Sir
- Page 571 and 572:
Chapter 17: Reporting for Duty, Sir
- Page 573 and 574:
Chapter 17: Reporting for Duty, Sir
- Page 575 and 576:
Chapter 17: Reporting for Duty, Sir
- Page 577 and 578:
Chapter 17: Reporting for Duty, Sir
- Page 579 and 580:
How It Works Chapter 17: Reporting
- Page 581 and 582:
18 Getting Integrated with Integrat
- Page 583 and 584:
Chapter 18: Getting Integrated with
- Page 585 and 586:
Chapter 18: Getting Integrated with
- Page 587 and 588:
Chapter 18: Getting Integrated with
- Page 589 and 590:
Examining Package Basics Fully exam
- Page 591 and 592:
Figure 18-12 Chapter 18: Getting In
- Page 593 and 594:
This brings up the OLE DB Source Ed
- Page 595 and 596:
Figure 18-17 Package Explorer This
- Page 597 and 598:
General Figure 18-19 Many fields on
- Page 599:
Executing the Package If you simply
- Page 602 and 603:
Chapter 19: Playing Administrator a
- Page 604 and 605:
Chapter 19: Playing Administrator Y
- Page 606 and 607:
Chapter 19: Playing Administrator 5
- Page 608 and 609:
Chapter 19: Playing Administrator 5
- Page 610 and 611:
Chapter 19: Playing Administrator 5
- Page 612 and 613:
Chapter 19: Playing Administrator 5
- Page 614 and 615:
Chapter 19: Playing Administrator A
- Page 616 and 617:
Chapter 19: Playing Administrator S
- Page 618 and 619:
Chapter 19: Playing Administrator R
- Page 620 and 621:
Chapter 19: Playing Administrator i
- Page 622 and 623:
Chapter 19: Playing Administrator P
- Page 625 and 626:
A System Functions SQL Server inclu
- Page 627 and 628:
@@IDLE Returns the time in millisec
- Page 629 and 630:
❑ CHECKSUM_AGG ❑ COUNT ❑ COUN
- Page 631 and 632:
GROUPING is only used in the SELECT
- Page 633 and 634:
❑ 4 — Thursday ❑ 5 — Friday
- Page 635 and 636:
If this evaluates to True, then you
- Page 637 and 638:
@@VERSION Returns the current versi
- Page 639 and 640:
DecryptByKey Like its asymmetric an
- Page 641 and 642:
SignByCert Returns a varbinary(8000
- Page 643 and 644:
If you are using the cursor variabl
- Page 645 and 646:
DAY The DAY function returns an int
- Page 647 and 648:
Yields: YEAR SELECT TODATETIMEOFFSE
- Page 649 and 650:
ABS ❑ LOG10 ❑ PI ❑ POWER ❑
- Page 651 and 652:
The expression must be of the float
- Page 653 and 654:
The expression must be of the float
- Page 655 and 656:
The id parameter specifies the ID o
- Page 657 and 658:
❑ ComparisonStyle — Indicates t
- Page 659 and 660:
❑ IsLogFile — The file is a log
- Page 661 and 662:
The return value from this function
- Page 663 and 664:
The return value from this function
- Page 665 and 666:
SQL_VARIANT_PROPERTY SQL_VARIANT_PR
- Page 667 and 668:
FREETEXTTABLE The FREETEXTTABLE fun
- Page 669 and 670:
IS_MEMBER The IS_MEMBER function re
- Page 671 and 672:
The user parameter is the username
- Page 673 and 674:
LEN The LEN function returns the nu
- Page 675 and 676:
SOUNDEX The SOUNDEX function return
- Page 677 and 678:
❑ NEWID ❑ NULLIF ❑ PARSENAME
- Page 679 and 680:
DATALENGTH The DATALENGTH function
- Page 681 and 682:
If you’re using identity columns
- Page 683 and 684:
SCOPE_IDENTITY The SCOPE_IDENTITY f
- Page 685 and 686:
The SERVERPROPERTY function is very
- Page 687 and 688:
B Very Simple Connectivity Examples
- Page 689 and 690:
Connecting in C# C# is a fairly cle
- Page 691 and 692:
} } Console.ReadLine(); // Change t
- Page 693 and 694:
Dim strCommand2 As String = “DROP
- Page 695 and 696:
SYMBOLS - (minus sign) for placehol
- Page 697 and 698:
B backup (databases) Back Up Databa
- Page 699 and 700:
constraints, 154-186 CHECK constrai
- Page 701 and 702:
database administration and mainten
- Page 703 and 704:
E editing properties and objects, 2
- Page 705 and 706:
fragmenting of indexes, 580 FREETEX
- Page 707 and 708:
ISDATE function, 607 IsDescendantOf
- Page 709 and 710:
NONCLUSTERED k eyword, 285 non-dete
- Page 711 and 712:
parentheses ( ) subqueries and, 188
- Page 713 and 714:
eport models, building. See report
- Page 715 and 716:
sp_help command, 131 sp_helpdb util
- Page 717 and 718:
adding foreign keys to, 162 adding
- Page 719 and 720:
U UDFs. See user-defined functions