SQL Bible ISBN:0764525840 by Alex Kriegel and Boris M Trukhnov John Wiley & Sons © 2003 (831 pages) This definitive volume contains all the information you need to understand and use SQL and its implementations in accordance with the established SQL99 standard CD Content Table of Contents SQL Bible Preface Part I - SQL Basic Concepts and Principles Chapter 1 Chapter 2 Chapter 3 - SQL and Relational Database Management Systems - Fundamental SQL Concepts and Principles - SQL Data Types Part II - Creating and Modifying Database Objects Chapter 4 Chapter 5 - Creating RDBMS Objects - Altering and Destroying RDBMS Objects Part III - Data Manipulation and Transaction Control Chapter 6 Chapter 7 - Data Manipulation Language (DML) - Sessions, Transactions, and Locks Part IV - Retrieving and Transforming Data Chapter 8 - Understanding SELECT Statement Chapter 9 - Multitable Queries Chapter 10 - SQL Functions Chapter 11 - SQL Operators Part V - Implementing Security Using System Catalogs Chapter 12 - SQL and RDBMS Security Chapter 13 - The System Catalog and INFORMATION_SCHEMA Part VI - Beyond SQL—Procedural Programming and Database Acc Chapter 14 Chapter 15 Chapter 16 Chapter 17 - Stored Procedures, Triggers, and User-Defined Func - Dynamic and Embedded SQL Overview - SQL API - New Developments—XML, OLAP, and Objects Part VII - Appendix Appendix A - What's on the CD-ROM Appendix B - The ACME Sample Database Appendix C - Basics of Relational Database Design Appendix D - Installing RDBMS Software Appendix E - Accessing RDBMS Appendix F - Installing the ACME Database Appendix G - SQL Functions Appendix H - SQL Syntax Reference Appendix I - SQL-Reserved Keywords Appendix J - SQL99 Major Features Compliance Across Different Appendix K - The Other RDBMS A Brief Introduction to the Number Systems, Boolea Appendix L Theory Index List of Figures List of Tables List of Code Examples List of Sidebars CD Content Back Cover Here, in one definitive volume, is all the information you need to understand and use SQL and its implementations in accordance with the established SQL99 standard Whether you want to learn database programming from scratch, you’d like to sharpen your SQL skills, or you need to know more about programming for a heterogeneous database environment, this book provides the complete menu Tutorials and code examples in each chapter make it an indispensable reference for every level of expertise Understand the definition and characteristics of relational databases and SQL’s role within RDBMS Recognize vendor-specific implementation variations among Oracle, IBM DB2 UDB, and MS SQL Server Create and modify RDBMS objects like tables, views, indexes, synonyms, sequences, and schemas using Data Definition Language (DDL) Comprehend Data Manipulation Language (DML) from different vendors’ perspectives Master single-table select statements and multitable queries from the ground up Explore in-depth SQL functions, operators, and data types for major RDBMS implementations Discover new SQL developments including XML, OLAP, Web services, and object-oriented features About the Authors Alex Kriegel, MCP/MCSD, has worked for Pope & Talbot, Inc., in Portland, Oregon, since 2001 as Senior Programmer/Analyst; prior to that, he worked for Psion Teklogix International, Inc., in the same capacity He received his B.S in Physics of Metals from Polytechnic Institute of Belarus in 1988, discovered PC programming in 1992, and has never looked back since He is also the author of Microsoft SQL Server 2000 Weekend Crash Course (Wiley, 2001) Boris M Trukhnov, OCP, has been working as Senior Technical Analyst/Oracle DBA for Pope & Talbot, Inc., in Portland, Oregon, since 1998 His previous job titles include Senior Programmer Analyst, Senior Software Developer, and Senior Operations Analyst He has been working with SQL and relational databases since 1994 Boris holds a B.S in Computer Science from the University of Minnesota SQL Bible Alex Kriegel and Boris M Trukhnov Published by Wiley Publishing, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2003 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada Library of Congress Control Number: 2003101832 ISBN: 0-7645-2584-0 10 9 8 7 6 5 4 3 2 1 1B/QU/QU/QT/IN No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8700 Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-Mail: permcoordinator@wiley.com LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR YOUR SITUATION YOU SHOULD CONSULT WITH A PROFESSIONAL WHERE APPROPRIATE NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S at (800) 762-2974, outside the U.S at (317) 572-3993 or fax (317) 572-4002 Wiley also publishes its books in a variety of electronic formats Some content that appears in print may not be available in electronic books Trademarks: Wiley, the Wiley Publishing logo and related trade dress are trademarks or registered trademarks of Wiley Publishing, Inc., in the United States and other countries, and may not be used without written permission IBM and DB2 are trademarks of IBM Corporation in the United States, other countries, or both Windows is a trademark of Microsoft Corporation in the United States, other countries, or both All other trademarks are the property of their respective owners Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book is a trademark of Wiley Publishing, Inc About the Authors Alex Kriegel, MCP/MCSD, has worked for Pope & Talbot, Inc., in Portland, Oregon, since 2001 as Senior Programmer/Analyst; prior to that, he worked for Psion Teklogix International, Inc., in the same capacity He received his B.S in Physics of Metals from Polytechnic Institute of Belarus in 1988, discovered PC programming in 1992, and has never looked back since He is also the author of Microsoft SQL Server 2000 Weekend Crash Course (Wiley, 2001) Boris M Trukhnov, OCP, has been working as Senior Technical Analyst/Oracle DBA for Pope & Talbot, Inc., in Portland, Oregon, since 1998 His previous job titles include Senior Programmer Analyst, Senior Software Developer, and Senior Operations Analyst He has been working with SQL and relational databases since 1994 Boris holds a B.S in Computer Science from the University of Minnesota Credits Acquisitions Editor: Jim Minatel Project Editor: Eric Newman Technical Editors: Ken Slovak Peter MacIntyre Copy Editor: Maarten Reilingh Editorial Manager: Mary Beth Wakefield Vice President & Executive Group Publisher: Richard Swadley Vice President and Executive Publisher: Bob Ipsen Vice President and Publisher: Joseph B Wikert Executive Editorial Director: Mary Bednarek Project Coordinator: Regina Snyder Graphics and Production Specialists: Beth Brooks Amanda Carter Jennifer Click Carrie Foster Joyce Haughey Kristin McMullan Quality Control Technician: Charles Spencer Media Development Specialist: Greg Stafford Proofreading and Indexing: TECHBOOKS Production Services I dedicate this book to the future of my sons, Phillip and Michael — Alex In loving memory of my mother — Boris Preface This book is about Structured Query Language Known familiarly as SQL, it is the standard language of relational databases and the lingua franca of the database world It has been around for more than 20 years and shows no signs of aging This is mostly because of numerous revisions: proprietary inventions frequently introduced by database vendors are either adopted into the standard, or become obsolete as the database community moves on The latest SQL standard was introduced in 1999, and even though ANSI/ISO SQL standards do exist, many of these standards remain rather theoretical and differ significantly from implementation to implementation That makes it difficult to find an SQL book "that has it all." One author might be biased toward a particular vendor so that you might get a decent Oracle or MS SQL Server book but not necessarily a good SQL one; a single explanation of all SQL ANSI/ISO standards alone would hardly be useful to anyone on a practical level We believe that only a combination of these two approaches can produce a good result Note The RDBMS world is divided between people who pronounce SQL as "ess-cue-ell" and those who pronounce it as "sequel." This book holds the former as the correct pronunciation, hence the usage "an SQL keyword" rather than "a SQL keyword." A comparison of modern database vendors shows that Oracle, IBM DB2, and Microsoft SQL Server have and are likely to continue to have the lion's share of the market This does not mean that other vendors are irrelevant Some features they offer can meet or even exceed those of the "big three" (as we call them); they have their devoted customers, and they are going to be around for years to come But because we cannot possibly cover each and every proprietary SQL extension, we decided to concentrate on the "big three" and explain SQL features with an emphasis on how they vary among Oracle, DB2, and MS SQL Server and how they differ from the SQL99 standard Note Sybase Adaptive Server SQL syntax is similar to the Microsoft SQL Server's syntax in many respects, and most of this book's MS SQL Server examples would also work with the Sybase ... Indianapolis, IN 46256 www .wiley. com Copyright © 2003 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada Library of Congress Control Number: 20031 01832 ISBN: 0-7645-2584-0... working with SQL and relational databases since 1994 Boris holds a B.S in Computer Science from the University of Minnesota SQL Bible Alex Kriegel and Boris M Trukhnov Published by Wiley Publishing, Inc... Appendix F - Installing the ACME Database Appendix G - SQL Functions Appendix H - SQL Syntax Reference Appendix I - SQL- Reserved Keywords Appendix J - SQL9 9 Major Features Compliance Across Different