Contents
T-SQL Fundamentals
Itzik Ben-Gan
T-SQL Fundamentals
Published with the authorization of Microsoft Corporation by:
Pearson Education, Inc.
Copyright 2023 by Itzik Ben-Gan.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions.
No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-13-810210-4
ISBN-10: 0-13-810210-4
Library of Congress Control Number: 2023930537
ScoutAutomatedPrintCode
Trademarks
Microsoft and the trademarks listed at http://www.microsoft.com on the Trademarks webpage are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author, the publisher, and Microsoft Corporation shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the programs accompanying it.
Special Sales
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact
.
For questions about sales outside the U.S., please contact
.
Editor-in-Chief
Brett Bartow
Executive Editor
Loretta Yates
Associate Editor
Charvi Arora
Development Editor
Songlin Qiu
Managing Editor
Sandra Schroeder
Senior Project Editor
Tracey Croom
Copy Editor
Scout Festa
Indexer
Erika Milllen
Proofreader
Jen Hinchliffe
Technical Editor
Lilach Ben-Gan
Editorial Assistant
Cindy Teeters
Cover Designer
Twist Creative, Seattle
Compositor
codeMantra
Pearsons Commitment to Diversity, Equity, and Inclusion
Pearson is dedicated to creating bias-free content that reflects the diversity of all learners. We embrace the many dimensions of diversity, including but not limited to race, ethnicity, gender, socioeconomic status, ability, age, sexual orientation, and religious or political beliefs.
Education is a powerful force for equity and change in our world. It has the potential to deliver opportunities that improve lives and enable economic mobility. As we work with authors to create content for every product and service, we acknowledge our responsibility to demonstrate inclusivity and incorporate diverse scholarship so that everyone can achieve their potential through learning. As the worlds leading learning company, we have a duty to help drive change and live up to our purpose to help more people create a better life for themselves and to create a better world.
Our ambition is to purposefully contribute to a world where:
Everyone has an equitable and lifelong opportunity to succeed through learning.
Our educational products and services are inclusive and represent the rich diversity of learners.
Our educational content accurately reflects the histories and experiences of the learners we serve.
Our educational content prompts deeper discussions with learners and motivates them to expand their own learning (and worldview).
While we work hard to present unbiased content, we want to hear from you about any concerns or needs with this Pearson product so that we can investigate and address them.
To Dato,
To live in hearts we leave behind,
Is not to die.
T HOMAS C AMPBELL
Acknowledgments
A number of people contributed to making this book a reality, either directly or indirectly, and deserve thanks and recognition. Its certainly possible I omitted some names unintentionally, and I apologize for this ahead of time.
To Lilach: Youre the one who makes me want to be good at what I do. Besides being my inspiration in life, you always take an active role in my books, helping to review the text for the first time. In this book, you took a more official technical editing role, and I cant appreciate enough the errors you spotted, and the many ideas and suggestions for improvements.
To my siblings, Mickey and Ina: Thank you for the constant support and for accepting the fact that Im away.
To Davide Mauri, Herbert Albert, Gianluca Hotz, and Dejan Sarka: Thanks for your valuable advice when I reached out asking for it.
To the editorial team at Pearson and related vendors. Loretta Yates, many thanks for being so good at what you do and for your positive attitude! Thanks to Charvi Arora for all your hard work and effort. Also, thanks to Songlin Qiu, Scout Festa, Karthik Orukaimani, and Tracey Croom for sifting through all the text and making sure its polished.
To my friends from Lucient, Fernando G. Guerrero, Herbert Albert, Fritz Lechnitz, and many others. Weve been working together for over two decades, and its been quite a ride!
To members of the Microsoft SQL Server development team, Umachandar Jayachandran (UC), Conor Cunningham, Kevin Farlee, Craig Freedman, Kendal Van Dyke, Derek Wilson, Davide Mauri, Bob Ward, Buck Woody, and Im sure many others. Thanks for creating such a great product, and thanks for all the time you spent meeting with me and responding to my emails, addressing my questions, and answering my requests for clarification.
To Aaron Bertrand, who besides being one of the most active and prolific SQL Server pros I know, does an amazing job editing the sqlperformance.com content, including my articles.
To Data Platform MVPs, past and present: Erland Sommarskog, Aaron Bertrand, Hugo Kornelis, Paul White, Alejandro Mesa, Tibor Karaszi, Simon Sabin, Denis Reznik, Tony Rogerson, and many othersand to the Data Platform MVP lead, Rie Merritt. This is a great program that Im grateful for and proud to be part of. The level of expertise of this group is amazing, and Im always excited when we all get to meet, both to share ideas and just to catch up at a personal level.