Apress.SQL.Server.2012.T-SQL.Recipes.3rd.Edition.Sep.2012.pdf

(6781 KB) Pobierz
THE EXPERT’S VOICE ® IN SQL SERVER
910450231.008.png
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
910450231.009.png 910450231.010.png 910450231.011.png 910450231.001.png 910450231.002.png 910450231.003.png 910450231.004.png 910450231.005.png
Contents at a Glance
About the Authors....................................................................................................... xlix
About the Technical Reviewers ..................................................................................... . li
Acknowledgments ........................................................................................................ liii
Introduction ................................................................................................................... lv
Chapter 1: Getting Started with SELECT
...................................................................... 1
Chapter 2: Elementary Programming
........................................................................ 23
Chapter 3: NULLs and Other Pitfalls
.......................................................................... 41
Chapter 4: Querying from Multiple Tables
................................................................. 57
Chapter 5: Grouping and Summarizing
..................................................................... 79
Chapter 6: Advanced Select Techniques
.................................................................... 93
Chapter 7: Aggregations and Windowing
................................................................ 115
Chapter 8: Inserting, Updating, Deleting
.................................................................. 147
Chapter 9: Working with Strings
............................................................................. 179
Chapter 10: Working with Dates and Times
............................................................ 197
Chapter 11: Working with Numbers
....................................................................... .219
Chapter 12: Transactions, Locking, Blocking, and Deadlocking
............................. . 241
Chapter 13: Managing Tables
.................................................................................. 273
Chapter 14: Managing Views
.................................................................................. . 301
Chapter 15: Managing Large Tables and Databases
............................................... . 319
Chapter 16: Managing Indexes
............................................................................... .341
iii
910450231.006.png
Contents at a GlanCe
Chapter 17: Stored Procedures
.............................................................................. . 363
Chapter 18: User-Defined Functions and Types
....................................................... 383
Chapter 19: Triggers
................................................................................................ 415
Chapter 20: Error Handling
...................................................................................... 447
Chapter 21: Query Performance Tuning
................................................................... 465
Chapter 22: Hints
.................................................................................................... .507
Chapter 23: Index Tuning and Statistics
................................................................. . 519
Chapter 24: XML
...................................................................................................... 539
Chapter 25: Files, Filegroups, and Integrity
........................................................... . 559
Chapter 26: Backup
................................................................................................ . 593
Chapter 27: Recovery
.............................................................................................. 621
Chapter 28: Principals and Users
........................................................................... .639
Chapter 29: Securables, Permissions, and Auditing
............................................... .673
Chapter 30: Objects and Dependencies
................................................................... 725
Index.......................................................................................................................... . 737
iv
Introduction
Sometimes all one wants is a good example. hat’s our motivation for accepting the baton from Joe Sack and
revising his excellent work to cover the very latest edition of Microsoft’s database engine—SQL Server 2012.
T-SQL is fundamental to working with SQL Server. Almost everything you do, from querying a table to
creating indexes to backing up and recovering, ultimately comes down to T-SQL statements being issued and
executed. Sometimes it’s a utility executing statements on your behalf. Other times you must write them yourself.
And when you have to write them yourself, you’re probably going to be in a hurry. Information technology
is like that. It’s a ield full of stress and deadlines, and don’t we all just want to get home for dinner with
our families?
We sure do want to be home for dinner, and that brings us full circle to the example-based format you’ll ind
in this book. If you have a job to do that’s covered in this book, you can count on a clear code example and very
few words to waste your time. We put the code irst! And explain it afterward. We hope our examples are clear
enough that you can just crib from them and get on with your day, but the detailed explanations are there if you
need them.
We’ve missed a few dinners from working on this book. We hope it helps you avoid the same fate.
Who This Book Is For
SQL Server 2012 T-SQL Recipes is aimed at developers deploying applications against Microsoft SQL Server
2012. he book also helps database administrators responsible for managing those databases. Any developer or
administrator valuing good code examples will ind something of use in this book.
Conventions
hroughout the book, we’ve tried to keep to a consistent style for presenting SQL and results. Where a piece of
code, a SQL reserved word, or a fragment of SQL is presented in the text, it is presented in ixed-width Courier
font, such as this example:
SELECT * FROM HumanResources.Employee;
Where we discuss the syntax and options of SQL commands, we use a conversational style so you can quickly
reach an understanding of the command or technique. We have chosen not to duplicate complex syntax
diagrams that are best left to the oicial, vendor-supplied documentation. Instead, we take an example-based
approach that is easy to understand and adapt.
Downloading the Code
he code for the examples shown in this book is available on the Apress web site, www.apress.com . A link can be
found on the book’s information page ( www.apress.com/9781430242000 ) on the Source Code/Downloads tab.
his tab is located in the Related Titles section of the page.
lv
910450231.007.png
Zgłoś jeśli naruszono regulamin