Pro T-SQL Programmer’s Guide

Pro T-SQL Programmer's Guide

4th Edition

Miguel Cebollero Jay Natarajan Michael Coles

Pro T-SQL Programmer's Guide

Copyright ? 2015 by Miguel Cebollero, Jay Natarajan, and Michael Coles

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law.

ISBN-13 (pbk): 978-1-4842-0146-6

ISBN-13 (electronic): 978-1-4842-0145-9

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Managing Director: Welmoed Spahr Lead Editor: Jonathan Gennick Technical Reviewer: Edgar Lanting Editorial Board: Steve Anglin, Gary Cornell, Louise Corrigan, Jim DeWolf, Jonathan Gennick,

Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing, Matt Wade, Steve Weiss Coordinating Editor: Jill Balzano Copy Editor: Tiffany Taylor Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Cover Designer: Anna Ishchenko

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-, or visit .

For information on translations, please e-mail rights@, or visit .

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales?eBook Licensing web page at bulk-sales.

Any source code or other supplementary materials referenced by the author in this text is available to readers at at 9781430245964. For detailed information about how to locate your book's source code, go to source-code/.

Contents at a Glance

About the Authors.xxiii About the Technical Reviewer.xxv Acknowledgmentsxxvii Introductionxxix Chapter 1: Foundations of T-SQL 1 Chapter 2: Tools of the Trade 19 Chapter 3: Procedural Code 47 Chapter 4: User-Defined Functions 79 Chapter 5: Stored Procedures 111 Chapter 6: In-Memory Programming 153 Chapter 7: Triggers 177 Chapter 8: Encryption 207 Chapter 9: Common Table Expressions and Windowing Functions 233 Chapter 10: Data Types and Advanced Data Types 269 Chapter 11: Full-Text Search 317 Chapter 12: XML 347 Chapter 13: XQuery and XPath 387 Chapter 14: Catalog Views and Dynamic aent Views 433 Chapter 15: .NET Client Programming 461 Chapter 16: CLR Integration Programming 511

iii

Contents at a Glance

Chapter 17: Data Services 559 Chapter 18: Error Handling and Dynamic SQL 589 Chapter 19: Performance Tuning 613 Appendix A: Exercise Answers 653 Appendix B: XQuery Data Types 663 Appendix C: Glossary 669 Appendix D: SQLCMD Quick Reference 683 Index 693

iv

Contents

About the Authors.xxiii About the Technical Reviewer.xxv Acknowledgmentsxxvii Introductionxxix

Chapter 1: Foundations of T-SQL 1 A Short History of T-SQL 1 Imperative vs. Declarative Languages 1 SQL Basics 3

Statements 3 Databases 5 Transaction Logs 5 Schemas 6 Tables 7 Views 8 Indexes 9 Stored Procedures 10 User-Defined Functions 10 SQL CLR Assemblies 10

Elements of Style 10

Whitespace 11 Naming Conventions 12 One Entry, One Exit 13

v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download