Share E-Book

SQL in a Nutshell A Desktop Quick Reference (Kevin Kline)(Z-Library)

Author Kevin Kline

sql
Language English

SQL in a Nutshell applies the classic O'Reilly "Nutshell" format to Structured Query Language (SQL), the elegant descriptive language that's used to create and manipulate stores of data. This book explains the purpose and proper syntax of hundreds of SQL statements, as defined in four major SQL implementations, and details each entry with explanatory text and illustrative examples. Perhaps best of all, authors Kevin and Daniel Kline feature MySQL in their coverage, and give it billing that's equal to that of Oracle, Microsoft SQL Server, and PostgreSQL. Their inclusion of open-source MySQL, which in most situations carries no license fee, is recognition of its growing popularity and suitability for serious database applications; also, it improves this book's appeal to Unix and Linux developers.The majority of this slender book comprises eminently useful syntax documentation (which is in the style of Unix man pages, with bracketed options and monospace arguments) and the other information that's specific to individual statements and functions. Additionally, it includes a relatively small amount of conceptual information, such as a section on the proper use of NULL values. The material that's not statement-specific also contrasts data-type implementations of the four covered platforms - for example, readers learn that a PostgreSQL int2 value is known as a smallint in ANSI standard SQL. This is a particularly handy reference book, if you use one of the emphasized SQL implementations.

Format PDF
Size 2.7 MB
6
Views
0
Downloads
0.00
Total Donations
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
IN A NUTSHELL A Desktop Quick Reference SOL sql_titlepg.qxd 10/13/00 5:27 PM Page 1
Page 2
sql_titlepg.qxd 10/13/00 5:27 PM Page 2
Page 3
Kevin Kline with Daniel Kline Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo IN A NUTSHELL A Desktop Quick Reference SOL sql_titlepg.qxd 10/13/00 5:27 PM Page 3
Page 4
SQL in a Nutshell by Kevin Kline with Daniel Kline Copyright © 2001 O’Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly & Associates, Inc., 101 Morris Street, Sebastopol, CA 95472. Editor: Gigi Estabrook Production Editor: Mary Sheehan Cover Designer: Ellie Volckhausen Printing History: January 2001: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly & Associates, Inc. The association between the image of a chameleon and the topic of SQL is a trademark of O’Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Library of Congress Cataloging-in-Publication Data Kline, Kevin E., 1966- SQL in a nutshell : a desktop quick reference/Kevin Kline with Daniel Kline. p. cm. Includes index. ISBN 1-56592-744-3 1. SQL server 2. SQL (Computer program language) 3. Client/server computing. I. Kline, Daniel. QA76.73.S67 K55 2000 005.75'85--dc21 00-065206 ISBN: 1-56592-744-3 [4/01] [M] ,COPYRIGHT.12247 Page iv Friday, March 23, 2001 10:05 AM
Page 5
About the Author Kevin Kline is the team leader for Information Architecture within Shared Informa- tion Services at Deloitte & Touche LLP. Kevin and his team perform data and infrastructure architecture in support of major knowledge management and transac- tion processing systems for Deloitte’s Client Service Technology organization. Kevin is also the author of Transact-SQL Programming (O’Reilly, 1999) (http:// www.oreilly.com/catalog/wintrnssql/ ) and numerous magazine articles on Microsoft SQL Server. When he’s not pulling his hair out over work issues, Kevin likes to romance his wife, play with his three kids, tinker with his ’66 Chevy pickup, and garden. Other than being Kevin’s brother, Daniel Kline is an Assistant Professor of English at the University of Alaska, Anchorage, where he specializes in medieval literature, liter- ary and cultural theory, and computer-assisted pedagogy. He completed his Ph.D. at Indiana University, Bloomington, and in addition to numerous scholarly presentations, Dan recently has published academic essays in Literary and Linguistic Computing, Philological Quarterly, Chaucer Review, and Essays in Medieval Studies. When he’s not spending time with his wife and two boys, Dan frets over his pet project, the Electronic Canterbury Tales (http://cwolf.uaa.alaska.edu/~afdtk/ext_main.htm). Dan can be reached at afdtk@ uaa.alaska.edu. Colophon Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of SQL in a Nutshell is a chameleon. There are approxi- mately 85 species of chameleons existing in the world today. They are mostly indigenous to Africa, although there are a few species found in Asia and in Europe. Most are tree dwellers. The chameleon is relatively small; the average adult size is between 6 inches and 12 inches. It lives mostly on insects, and uses its long tongue to capture its prey. Indeed, the tongue is a critical tool. It can stretch up to 1.5 times the lizard’s body length, and there is an adhesive pad on the end, which the insects are trapped on. There are several other characteristics common to all species of cha- meleons. For example, its eyes are large and protruding, and the lizard can see 360 degrees around without moving its head or body. Its toes are on either side of its feet, usually with three on one side and two on the other. This is ideal for moving quickly and efficiently through tree branches. Chameleons are best known for their ability to change their appearance to adapt to their physical environment. Actually, several types of reptiles can change their skin color, but the chameleon is far and away the most accomplished. This skill, which is moderated by the nervous system, obviously is invaluable for hunting prey and avoiding predators, and also helps to stablize body temperature. The extent of this camouflage capability is related to the gender, age, and species of the lizard. ,AUTHOR.COLO.12098 Page 1 Friday, March 23, 2001 10:05 AM
Page 6
Mary Sheehan was the production editor and proofreader for SQL in a Nutshell, and Jeffrey Holcomb was the copyeditor. Emily Quill and Colleen Gorman provided quality control. Linley Dolby provided production assistance. Brenda Miller wrote the index. Ellie Volckhausen designed the cover of this book, based on a series design by Edie Freedman. The cover image is a 19th-century engraving from the Dover Pictorial Archive. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe’s ITC Garamond font. Melanie Wang designed the interior layout based on a series design by Nancy Priest. The text and heading fonts are ITC Garamond Light and Garamond Book. The illus- trations that appear in the book were produced by Robert Romano using Macromedia FreeHand 8 and Adobe Photoshop 5. This colophon was written by Mary Sheehan. Whenever possible, our books use a durable and flexible lay-flat binding. If the page count exceeds this binding’s limit, perfect binding is used. ,AUTHOR.COLO.12098 Page 2 Friday, March 23, 2001 10:05 AM
Page 7
iii Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Table of Contents Preface ........................................................................................................ v Chapter 1—SQL, Vendor Implementations, and Some History ........................................................................... 1 The Relational Database Model ............................................................. 1 The Databases Described in This Book ................................................ 2 The SQL Standard ................................................................................... 2 Dialects of SQL ....................................................................................... 6 Principles of Relational Databases ......................................................... 7 Chapter 2—Foundational Concepts ............................................... 9 Row Processing Versus Set Processing ................................................. 9 The Relational Model ........................................................................... 10 SQL99 and Vendor-Specific Datatypes ................................................ 10 Processing NULLS ................................................................................. 18 Categories of Syntax ............................................................................. 19 Using SQL ............................................................................................. 23 Conclusion ............................................................................................ 26 Chapter 3—SQL Statements Command Reference ................ 27 Recommended Reading Approach ...................................................... 27 Quick SQL Command Reference ......................................................... 27 DROP Statements ................................................................................. 96 Conclusion .......................................................................................... 162 ,sql_ianTOC.fm.14129 Page iii Wednesday, November 29, 2000 4:45 PM
Page 8
iv Table of Contents Computer Crime: A Crimefighter’s Handbok, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Chapter 4—SQL Functions ............................................................ 163 Deterministic and Nondeterministic Functions ................................. 163 Types of Functions ............................................................................. 164 Vendor Extensions ............................................................................. 175 Chapter 5—Unimplemented SQL99 Commands ................. 194 Appendix—SQL99 and Vendor-Specific Keywords ............... 197 Index ...................................................................................................... 205 ,sql_ianTOC.fm.14129 Page iv Wednesday, November 29, 2000 4:45 PM
Page 9
v Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Preface The explosive growth of the information technology industry and the constantly growing need to compile, store, access, and manipulate increasingly larger masses of data have required the development of ever more sophisticated database management tools. Since its first incarnation in the 1970s, Structured Query Language (SQL) has been developed hand in hand with the information boom, and as a result, is the most widely used database manipulation language in business and industry. A number of different software companies and program developers, including those in the open source movement, have concurrently developed their own SQL dialects in response to specific needs. All the while, standards bodies have developed a growing list of common features. SQL in a Nutshell identifies the differences between the various vendor implemen- tations of SQL. Readers will find a concise explanation of the Relational Database Management System (RDBMS) model, a clear-cut explanation of foundational RDBMS concepts, and thorough coverage of basic SQL syntax and commands. Most importantly, programmers and developers who use SQL in a Nutshell will find a concise guide both to the most popular commercial database packages on the market (Microsoft SQL Server and Oracle8i), and to two of the best known open source (http://www.opensource.org) database products (MySQL and PostgreSQL). SQL in a Nutshell ’s attention to open source SQL products is an affir- mation of the growing importance of the open source movement within the computing community. As a result, SQL in a Nutshell benefits several distinct groups of users: the knowl- edgeable programmer who requires a concise and handy reference tool, the developer who needs to migrate from one SQL dialect to another, and the user who comes to SQL from another programming language and wants to learn the basics of SQL programming. ,ch00.13241 Page v Wednesday, November 29, 2000 4:41 PM
Page 10
vi Preface How This Book Is Organized Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. How This Book Is Organized This book is divided into five chapters and one appendix: Chapter 1, SQL, Vendor Implementations, and Some History This chapter discusses the Relational Database Model, describes the current and previous SQL standards, and introduces the SQL vendor implementations covered in this book. Chapter 2, Foundational Concepts This chapter describes the fundamental concepts necessary for understanding relational databases and SQL commands. Chapter 3, SQL Statements Command Reference This chapter is an alphabetical command reference. It details each SQL99 command, as well as the implementations of each command by Oracle, Microsoft SQL Server, MySQL, and PostgreSQL. Chapter 4, SQL Functions This chapter is an alphabetical reference of the SQL99 functions, describing vendor implementations of these functions and vendor extensions. Chapter 5, Unimplemented SQL99 Commands This chapter lists commands that are included in the SQL standards, but have not yet been implemented by any of the vendors. Appendix, SQL99 and Vendor-Specific Keywords The appendix provides a table that displays keywords declared in SQL99 and by the various database vendors. Conventions Used in This Book Constant Width Used to indicate programming syntax, code fragments, and examples. Italic Used to introduce new terms, for emphasis, and to indicate commands or user-specified file and directory names. Bold Used to display the names of database objects, such as tables, columns, and stored procedures. UPPERCASE Used to indicate SQL keywords. The owl icon indicates a tip, suggestion, or general note. ,ch00.13241 Page vi Wednesday, November 29, 2000 4:41 PM
Page 11
Preface vii Preface Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. The turkey icon indicates a warning or caution. How to Contact Us We have tested and verified the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes!). Please let us know about any errors you find, as well as your sugges- tions for future editions, by writing to: O’Reilly & Associates 101 Morris Street Sebastopol, CA 95472 (800) 998-9938 (in the U.S. or Canada) (707) 829-0515 (international/local) (707) 829-0104 (fax) We have a web site for the book, where we’ll list any examples, errata, or plans for future editions. You can access this page at: http://www.oreilly.com/catalog/sqlnut/ To ask technical questions or to comment on the book, send email to: bookquestions@oreilly.com For more information about our books, conferences, software, Resource Centers, and the O’Reilly Network, see the O’Reilly web site: http://www.oreilly.com Resources The following web sites provide additional information about the various vendors covered in this book: MySQL The corporate resource for MySQL is http://www.tcx.se. A great developer resource with lots of useful tips is Devshed.com: see http://www.devshed.com/ Server_Side/MySQL/ for MySQL-specific information. Microsoft SQL Server The official Microsoft SQL Server web site is http://www.microsoft.com/sql/. Microsoft also hosts a strong technical site for SQL Server at http://www. microsoft.com/technet/sql/default.htm. Another good resource is found at the home of the Professional Association for SQL Server (PASS) at http://www. sqlpass.org. ,ch00.13241 Page vii Wednesday, November 29, 2000 4:41 PM
Page 12
viii Preface Acknowledgments Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. PostgreSQL The home for this open source database is located at http://www.postgresql.org. This site contains a great deal of useful information available for download, as well as mailing lists that enable exchanges with other PostgreSQL users. Addi- tional PostgreSQL sites worth investigating are http://www.pgsql.com and http:// www.GreatBridge.com, which offer support for commercial customers. Oracle Oracle’s cyberspace home is http://www.oracle.com. A great resource for hard- core Oracle users is http://technet.oracle.com. Acknowledgments We’d like to take a moment to thank a few special individuals at O’Reilly & Associates. First, we owe a huge debt of gratitude to Gigi Estabrook, the initial editor of this book, and Robert Denn, the ultimate editor of this book. Gigi’s outstanding work and caring attitude were always refreshing and rejuvenating. Robert’s attention to detail and exceptional management skills are the reason this book is here today. Thank you both! And of course, thanks to Tim O’Reilly for having a direct hand in the birth of this book. We also owe a debt to our fine technical reviewers. To Thomas Lockhard (PostgreSQL and SQL99), Matthew Toennies and Jonathan Gennick (Oracle), Baya Pavliachvili and Ron Talmage (Microsoft SQL Server), and George Reese (MySQL): we owe you a hearty thanks! Your contributions have greatly improved the accu- racy, readability, and value of this book. Without you, our sections on each of the language extensions would have been on shaky ground. ,ch00.13241 Page viii Wednesday, November 29, 2000 4:41 PM
Page 13
1 History Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Chapter 1History CHAPTER 1 SQL, Vendor Implementations, and Some History In the 1970s, IBM developed a product called SEQUEL, or Structured English Query Language, which ultimately became SQL, the Structured Query Language. IBM, along with other relational database vendors, wanted a standardized method for accessing and manipulating data in a relational database. Over the decades, many competing languages have allowed programmers and developers to access and manipulate data. However, few have been as easy to learn and as universally accepted as SQL. Programmers and developers now have the benefit of learning a language that, with minor adjustments, is applicable to a wide variety of database applications and products. SQL in a Nutshell describes four implementations of the current SQL standard, SQL99 (also known as SQL3): Microsoft’s SQL Server, MySQL, Oracle, and PostgreSQL. For those migrating from implementations of the earlier SQL stan- dard, this chapter describes the current SQL standard and the ways in which it differs from the earlier standard. This chapter also provides a bit of history of the standards evolution. The Relational Database Model Relational Database Management Systems (RDBMSs), such as SQL Server and Oracle, are the primary engines of information systems worldwide, particularly Internet/Intranet applications and distributed client/server computing systems. An RDBMS is defined as a system whose users view data as a collection of tables related to each other through common data values. Data is stored in tables, and tables are composed of rows and columns. Tables of independent data can be linked (or related) to one another if they each have columns of data (called keys) that represent the same data value. This concept is so common as to seem trivial; however, it was not so long ago that achieving and programming a system capable of sustaining the relational model was considered a long shot that would have limited usefulness. ,ch01.13361 Page 1 Wednesday, November 29, 2000 4:41 PM
Page 14
2 Chapter 1 – SQL, Vendor Implementations, and Some History The Databases Described in This Book Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Relational data theory was developed by E. F. Codd in the 1960s. Codd compiled a list of criteria a database product must meet to be considered rela- tional. For those who are curious, Codd’s list appears at the end of this chapter. The Databases Described in This Book SQL in a Nutshell describes the SQL standard and the vendor implementa- tions of four leading RDBMSs—two that are from leading commercial vendors (Microsoft SQL Server and Oracle) and two that are from the chief open source database projects (MySQL and PostgreSQL): Microsoft SQL Server Microsoft SQL Server is a popular RDBMS that runs only on the Windows platform. Its features include ease of use, low cost, and high performance. This book covers Microsoft SQL Server 2000. MySQL MySQL is a popular open source Database Management System (DBMS) that is known for its blistering performance. It runs on numerous operating systems, including most Linux variants. To improve performance, it has a slimmer feature set than do many other DBMSs. Its critics point out that it is not a fully relational DBMS since it does not support many key features of relational databases, particularly in how it processes transactions. This book covers MySQL 3.22.9. Oracle Oracle is a leading RDBMS in the commercial sector. It runs on a multitude of operating systems and hardware platforms. Its scalable and reliable architec- ture have made it the platform of choice for many users. Because of their highly tunable nature, Oracle RDBMSs require a well-trained database admin- istrator (DBA). SQL in a Nutshell covers Oracle Release 8.1. PostgreSQL PostgreSQL is one of the most feature-rich RDBMSs of the open source world. Its compliance with SQL standards is unmatched by other open source RDBMSs. In addition to its rich set of features, PostgreSQL runs on a wide variety of operating systems and hardware platforms. This book covers PostgreSQL 6.5. The SQL Standard To bring greater conformity among vendors, the American National Standards Institute (ANSI) published its first SQL standard in 1986 and a second widely adopted standard in 1989. ANSI released updates in 1992, known as SQL92 and SQL2, and again in 1999, termed both SQL99 and SQL3. Each time, ANSI added new features and incorporated new commands and capabilities into the language. Unique to the SQL99 standard is a group of capabilities that handle object-oriented datatype extensions. The International Standards Organization (ISO) has also ,ch01.13361 Page 2 Wednesday, November 29, 2000 4:41 PM
Page 15
The SQL Standard 3 History The SQL Standard Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. approved SQL99. An important change from SQL92 is that SQL99 expands on SQL92’s levels of conformance. Levels of Conformance SQL92 first introduced levels of conformance by defining three categories: Entry, Intermediate, and Full. Vendors had to achieve Entry-level conformance to claim ANSI SQL compliance. The U.S. National Institute of Standards and Technology (NIST) later added the Transitional level between the Entry and Intermediate levels. So, NIST’s levels of conformance were Entry, Transitional, Intermediate, and Full, while ANSI’s were only Entry, Intermediate, and Full. Each higher level of the standard was a superset of the subordinate level, meaning that each higher level of the standard included all the features of the lower level of conformance. SQL99 altered the base levels of conformance. Gone are the Entry, Intermediate, and Full levels of conformance. With SQL99, vendors must implement all the features of the lowest level of conformance, Core SQL:1999, in order to claim (and publish) that they are SQL99 ready. Core SQL:1999—or Core SQL99, for short— includes the old Entry SQL92 feature set, features from other SQL92 levels, and some brand new features. This upgrade to the SQL standard enabled vendors to go quickly from the Entry SQL92 feature set to the Core SQL99 feature set. Whereas SQL92 featured the Intermediate and Full levels of conformance, SQL99 has Enhanced SQL:1999. Any DBMS that supports the Core SQL99 benchmarks, plus one or more of nine additional feature packages, is now said to meet Enhanced SQL:1999 standards defined in SQL99 (also called Enhanced SQL99). Supplemental Features Packages The SQL99 standard represents the ideal, but very few vendors immediately meet or exceed the Core SQL99 requirements. The Core SQL99 standard is like the inter- state speed limit: some drivers go above, others go below, but few go exactly the speed limit. Similarly, vendor implementations can vary greatly. Two committees—one within ANSI and the other within ISO—composed of representatives from virtually every RDBMS vendor drafted these definitions. In this collaborative and somewhat political environment, vendors must compromise on exactly which proposed feature and implementation will be incorporated into the new standard. Many times, a new feature in the ANSI standard is derived from an existing product or is the outgrowth of new research and development from the academic community. Consequently, many vendors adopt some features in the standard, and later add still more. The nine supplemental features packages, representing different subsets of commands, are vendor-optional. Some SQL99 features might show up in multiple packages, while others do not appear in any of the packages. These packages and their features are described in Table 1-1. ,ch01.13361 Page 3 Wednesday, November 29, 2000 4:41 PM
Page 16
4 Chapter 1 – SQL, Vendor Implementations, and Some History The SQL Standard Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Table 1-1: SQL99 Supplemental Features Packages ID Name Features PKG001 Enhanced datetime facilities • Interval datatype • Time zone specification • Full datetime • Optional interval qualifier PKG002 Enhanced integrity management • Assertions • Referential delete actions • Referential update actions • Constraint management • Subqueries in CHECK constraint • Triggers • FOR EACH STATEMENT triggers • Referential action RESTRICT PKG003 OLAP capabilities • CUBE and ROLLUP • INTERSECT operator • Row and table constructs • FULL OUTER JOIN • Scalar subquery values PKG004 SQL Persistent Stored Modules (PSM) • A programmatic extension to SQL that makes it suitable for developing more functionally complete applications • The commands CASE, IF, WHILE, REPEAT, LOOP, and FOR • Stored Modules • Computational completeness • INFORMATION_SCHEMA views PKG005 SQL Call-level Interface (CLI) • SQL Call-level Interface support: an Application Programming Interface (API) that enables SQL operations to be called that is very similar to the Open Database Connectivity (ODBC) standard PKG006 Basic object support • Overloading SQL-invoked functions and procedures • User-defined types with single inheritance; basic SQL routines on user-defined types (including dynamic dispatch) • Reference types • CREATE TABLE • Array support: basic array support, array expressions, array locators, user-datatype (UDT) array support, reference-type array support, SQL routine on arrays • Attribute and field reference • Reference and dereference operations PKG007 Enhanced object support • ALTER TABLE, ADD • Enhanced user-defined types (including constructor options, attribute defaults, multiple inheritance, and ordering clause) • SQL functions and type-name resolution • Subtables • ONLY in queries • Type predicate • Subtype treatment • User-defined CAST functions • UDT locators • SQL routines on user-defined types such as identity functions and generalized expressions ,ch01.13361 Page 4 Wednesday, November 29, 2000 4:41 PM
Page 17
The SQL Standard 5 History The SQL Standard Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Be aware that a DBMS vendor may claim Enhanced SQL99 compliance by meeting Core SQL99 standards plus only one of nine added packages; so read the vendor’s fine print for a full description of its program features. By understanding what features comprise the nine packages, programmers and developers gain a clear idea of the capabilities of a particular DBMS, and how the various features behave when SQL code is transported to other database products. The ANSI standards—which cover retrieval, manipulation, and management of data in commands, such as SELECT, JOIN, ALTER TABLE, and DROP—formalized many SQL behaviors and syntax structures across a variety of products. These standards become even more important as open source database products, such as MySQL, miniSQL, and PostgreSQL, grow in popularity and are developed by virtual teams rather than large corporations. SQL in a Nutshell explains the SQL implementation of four popular RDBMSs. These vendors do not meet all the SQL99 standards; in fact, all RDBMS vendors play a constant game of tag with the standards bodies. Many times, as soon as vendors close in on the standard, the standards bodies update, refine, or other- wise change the benchmark. SQL99 Statement Classes Comparing statement classes further delineates SQL92 and SQL99. In SQL92, SQL statements are grouped into three broad categories: the Data Manipulation Language (DML), the Data Definition Language (DDL), and the Data Control Language (DCL). The DML provides specific data-manipulation commands such as SELECT, INSERT, UPDATE, and DELETE. The DDL contains commands that handle the accessibility and manipulation of database objects, including CREATE and DROP, while the DCL contains the permission-related commands GRANT and REVOKE. In contrast, SQL99 supplies seven Core categories that provide a general frame- work for the types of commands available in SQL. These statement “classes” are slightly different than the SQL92 statement classes, since they attempt to identify the statements within each class more accurately and logically. Furthermore, because SQL is constantly under development, new features and commands enter the standard and may necessitate new statement classes. So, to accommodate future growth, SQL99 developed new sets of statement classes, making them somewhat more comprehensible and logical. Additionally, the new statement classes now allow some “orphaned” statements—which did not fit well into any of the old categories—to be properly classified. PKG008 Active database features • Triggers PKG009 SQL Multimedia (MM) support • Handling for streaming multimedia data and for large and complex audio and video data Table 1-1: SQL99 Supplemental Features Packages (continued) ID Name Features ,ch01.13361 Page 5 Wednesday, November 29, 2000 4:41 PM
Page 18
6 Chapter 1 – SQL, Vendor Implementations, and Some History Dialects of SQL Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Table 1-2 identifies the SQL99 statement classes and lists a few commands in each class, each of which is fully discussed later. At this point, the key is to remember the statement class title. Those who work with SQL regularly should become familiar with both the old (SQL92) and the new (SQL99) statement classes, since many programmers and developers still use the old nomenclature to refer to current SQL features. Dialects of SQL The constantly evolving nature of the SQL standard has given rise to a number of SQL dialects among the various vendors and products. These dialects most commonly evolved because the user community of a given database vendor required capabilities in the database before the ANSI committee created a stan- dard. Occasionally though, a new feature is introduced by the academic or research communities due to competitive pressures from competing technologies. For example, many database vendors are augmenting their current programmatic offerings with Java (as is the case with Oracle and Sybase) or VBScript (as Microsoft is doing). In the future, programmers and developers will use these programming languages in concert with SQL to build SQL programs. Nonetheless, each of these dialects includes conditional processing (such as that controlled through IF . . . THEN statements), control-of-flow functions (such as WHILE loops), variables, and error handling. Because ANSI had not yet developed a standard for these important features, RDBMS developers and vendors were free to create their own commands and syntax. In fact, some of the earliest vendors from the 1980s have variances in the most elementary commands, such as SELECT, because their implementations predate the standards. (ANSI is now refining stan- dards that address these shortcomings.) Some of these dialects have introduced procedural commands to support the func- tionality of a much more complete programming language. For example, these procedural implementations contain error-handling commands, control-of-flow Table 1-2: SQL Statement Classes Class Description Example Commands SQL Connection Statements Start and end a client connection CONNECT, DISCONNECT SQL Control Statements Control the execution of a set of SQL statements CALL, RETURN SQL Data Statements Have a persistent and enduring effect upon data SELECT, INSERT, UPDATE, DELETE SQL Diagnostic Statements Provide diagnostic information and raise exceptions and errors GET DIAGNOSTICS SQL Schema Statements Have a persistent and enduring effect on a database schema and objects within that schema ALTER, CREATE, DROP SQL Session Statements Control default behavior and other parameters for a session SET SQL Transaction Statements Set the starting and ending point of a transaction COMMIT, ROLLBACK ,ch01.13361 Page 6 Wednesday, November 29, 2000 4:41 PM
Page 19
Principles of Relational Databases 7 History Principles of Relational Databases Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. language, conditional commands, variable handling, arrays, and many other exten- sions. Although these are technically divergent procedural implementations, they are called dialects here. Some popular dialects of SQL include: PL/SQL Found in Oracle. PL/SQL stands for Procedural Language/SQL and contains many similarities to the language Ada. Transact-SQL Uses both Microsoft SQL Server and Sybase Adaptive Server. As Microsoft and Sybase have moved away from the common platform they shared early in the 1990s, their implementations of Transact-SQL have also diverged. PL/pgSQL The name of the SQL dialect and extensions implemented in PostgreSQL. The acronym stands for Procedural Language/postgreSQL. However, even if a vendor conforms to the SQL99 standards, its commands differ from other DBMSs because SQL statements may be parsed, compiled, and executed in different ways, especially if differing binding styles are used. There are three common binding styles: SQL Module Language Causes the SQL statements to be prepared when the module is created, and executed when the module is called (like a stored procedure). Embedded SQL Syntax Allows the SQL statements to be prepared when the host language program is precompiled, and executed when the host program is called (like PRO*C or PRO*Fortran). Direct SQL Invocation Causes a static SQL statement to be prepared then immediately executed. Therefore, differences in binding style may be one more reason DBMSs function differently. Binding styles go deep into the heart of the database code. In general, the SQL commands discussed in this book utilize the Direct SQL Invocation binding style. However, when the situation warrants, other relevant binding styles are discussed within the command reference of each specific command. Principles of Relational Databases Following are E.F. Codd’s Twelve Principles of Relational Databases. These princi- ples continue to be the litmus test used to validate the “relational” characteristics of a database product; a database product that does not meet all of these rules is not fully relational. These rules do not apply to applications development, but they do determine whether the database engine itself can be considered truly “relational.” Currently, most RDBMSs pass Codd’s test, including all of the databases discussed in this book, except MySQL. (MySQL does not currently support views or atomic transactions. Therefore, it does not qualify as a true relational DBMS under Codd’s rules.) ,ch01.13361 Page 7 Wednesday, November 29, 2000 4:41 PM
Page 20
8 Chapter 1 – SQL, Vendor Implementations, and Some History Principles of Relational Databases Book Title, eMatter Edition Copyright © 2000 O’Reilly & Associates, Inc. All rights reserved. Knowing and understanding these principles assists programmers and developers in the proper development and design of Relational Databases (RDBs). Codd’s Rules for a Truly Relational Database System Codd’s criteria provide the benchmarks for defining RDBs. Knowing and understanding these principles will help you develop and design RDBs: 1. Information is represented logically in tables. 2. Data must be logically accessible by table, primary key, and column. 3. Null values must be uniformly treated as “missing information,” not as empty strings, blanks, or zeros. 4. Metadata (data about the database) must be stored in the database just as regular data is. 5. A single language must be able to define data, views, integrity constraints, authorization, transactions, and data manipulation. 6. Views must show the updates of their base tables and vice versa. 7. A single operation must be able to retrieve, insert, update, or delete data. 8. Batch and end-user operations are logically separate from physical storage and access methods. 9. Batch and end-user operations can change the database schema without having to recreate it or the applications built upon it. 10. Integrity constraints must be available and stored in the RDB metadata, not in an application program. 11. The data manipulation language of the relational system should not care where or how the physical data is distributed and should not require alteration if the physical data is centralized or distributed. 12. Any row processing done in the system must obey the same integrity rules and constraints that set-processing operations do. ,ch01.13361 Page 8 Wednesday, November 29, 2000 4:41 PM
The above is a preview of the first 20 pages. Register to read the complete e-book.

Support Author

0.00
Total Amount (¥)
0
Donation Count
Please enter an amount Minimum ¥1

You will be redirected to Alipay to complete payment, then return here.

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List