100% found this document useful (2 votes)
7 views

SQL The Complete Reference 2nd Edition James R. Groff download

The document provides information about various eBooks available for download, including 'SQL: The Complete Reference, 2nd Edition' by James R. Groff and Paul N. Weinberg. It includes links to other titles and details about the authors and technical editor. Additionally, it outlines the contents and structure of the SQL reference book, emphasizing its features and benefits.

Uploaded by

lkcpercaz61
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
7 views

SQL The Complete Reference 2nd Edition James R. Groff download

The document provides information about various eBooks available for download, including 'SQL: The Complete Reference, 2nd Edition' by James R. Groff and Paul N. Weinberg. It includes links to other titles and details about the authors and technical editor. Additionally, it outlines the contents and structure of the SQL reference book, emphasizing its features and benefits.

Uploaded by

lkcpercaz61
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

SQL The Complete Reference 2nd Edition James R.

Groff pdf download

https://ebookname.com/product/sql-the-complete-reference-2nd-
edition-james-r-groff/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Web Design Complete Reference 2nd Edition Thomas A.


Powell

https://ebookname.com/product/web-design-complete-reference-2nd-
edition-thomas-a-powell/

C The Complete Reference Herbert Schildt

https://ebookname.com/product/c-the-complete-reference-herbert-
schildt/

Red Hat Linux 7 2 The Complete Reference 2nd Edition


Richard Petersen

https://ebookname.com/product/red-hat-linux-7-2-the-complete-
reference-2nd-edition-richard-petersen/

The Great Pacific Garbage Patch 1st Edition Laura


Perdew

https://ebookname.com/product/the-great-pacific-garbage-
patch-1st-edition-laura-perdew/
The Discourse of Sovereignty Hobbes to Fielding The
State of Nature and the Nature of the State 1st Edition
Stuart Sim

https://ebookname.com/product/the-discourse-of-sovereignty-
hobbes-to-fielding-the-state-of-nature-and-the-nature-of-the-
state-1st-edition-stuart-sim/

Making New Words Morphological Derivation in English R.


M. W Dixon

https://ebookname.com/product/making-new-words-morphological-
derivation-in-english-r-m-w-dixon/

Green Polymer Chemistry Biocatalysis and Biomaterials


1st Edition H. N. Cheng

https://ebookname.com/product/green-polymer-chemistry-
biocatalysis-and-biomaterials-1st-edition-h-n-cheng/

The Little SAS Book A Primer Fifth Edition Lora


Delwiche

https://ebookname.com/product/the-little-sas-book-a-primer-fifth-
edition-lora-delwiche/

Dreamers of a New Day Women Who Invented the Twentieth


Century Sheila Rowbotham

https://ebookname.com/product/dreamers-of-a-new-day-women-who-
invented-the-twentieth-century-sheila-rowbotham/
Building High Performance Business Relationships Rescue
Improve and Transform Your Most Valuable Assets 1st
Edition Tony Lendrum

https://ebookname.com/product/building-high-performance-business-
relationships-rescue-improve-and-transform-your-most-valuable-
assets-1st-edition-tony-lendrum/
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9
Blind Folio i

SQL:
The Complete Reference,
Second Edition

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:05 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9
Blind Folio ii

About the Authors


James R. Groff is president and CEO of TimesTen,
a software company that delivers real-time event
processing software to telecom, financial services,
and e-business customers. The core of the TimesTen
software is a high-performance, memory-optimized,
SQL-based DBMS. Prior to joining TimesTen, Groff
was the cofounder, with Paul Weinberg, of Network
Innovations Corporation, a developer of SQL-based
networking software, and coauthor of Understanding
UNIX: A Conceptual Guide and SQL: The Complete
Reference. He has also held senior division management
and marketing positions at Apple Computer and
Hewlett-Packard. Groff holds a B.S. in mathematics
from the Massachusetts Institute of Technology and
an M.B.A. from Harvard University.

Paul N. Weinberg is president and CEO of A2i,


Inc., a software company that develops and markets
a system for enterprise-wide product content
management and single-source, cross-media catalog
publishing. Before that, he was the cofounder, with
Jim Groff, of Network Innovations Corporation, an
early pioneer in client/server database access that
was acquired by Apple Computer, Inc., in 1988, and
the coauthor of Understanding UNIX: A Conceptual
Guide and SQL: The Complete Reference. He has also
held software development and marketing positions
at Bell Laboratories, Hewlett-Packard, and Plexus
Computers. In 1981, he collaborated on The Simple
Solution to Rubik’s Cube, the number-one best-selling
book of that year with over six million copies sold.
He holds a B.S. from the University of Michigan
and an M.S. from Stanford University, both in
Computer Science.

About the Technical Editor


Greg Guntle has been doing technical editing of
computer books for 20 years. He has written several
programming books as well.

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:06 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9
Blind Folio iii

SQL:
The Complete Reference,
Second Edition
James R. Groff and Paul N. Weinberg

McGraw-Hill/Osborne
New York Chicago San Francisco
Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:06 PM
ebook_copyright 6x9.qxd 12/19/02 4:06 PM Page 1

Copyright © 2002 by The McGraw-HIll Companies, Inc. All rights reserved. Manufactured in the
United States of America. Except as permitted under the United States Copyright Act of 1976, no part
of this publication may be reproduced or distributed in any form or by any means, or stored in a data-
base or retrieval system, without the prior written permission of the publisher.

0-07-222817-2

The material in this eBook also appears in the print version of this title: 0-07-222559-9

All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after
every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit
of the trademark owner, with no intention of infringement of the trademark. Where such designations
appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales pro-
motions, or for use in corporate training programs. For more information, please contact George
Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069.

TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors
reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted
under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not
decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon,
transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without
McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use;
any other use of the work is strictly prohibited. Your right to use the work may be terminated if you
fail to comply with these terms.
THE WORK IS PROVIDED “AS IS”. McGRAW-HILL AND ITS LICENSORS MAKE NO GUAR-
ANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF
OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMA-
TION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE,
AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the func-
tions contained in the work will meet your requirements or that its operation will be uninterrupted or
error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inac-
curacy, error or omission, regardless of cause, in the work or for any damages resulting therefrom.
McGraw-Hill has no responsibility for the content of any information accessed through the work.
Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental,
special, punitive, consequential or similar damages that result from the use of or inability to use the
work, even if any of them has been advised of the possibility of such damages. This limitation of lia-
bility shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort
or otherwise.

DOI: 10.1036/0072228172
DOI Page 6x9 10/2/02 1:33 PM Page 1

Want to learn more?


,
We hope you enjoy this McGraw-Hill eBook! If you d like
more information about this book, its author, or related books
and websites, please click here.
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter
FM:v

For more information about this title, click here.

Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Part I
An Overview of SQL
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The SQL Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Role of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
SQL Features and Benefits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Vendor Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Portability Across Computer Systems . . . . . . . . . . . . . . . . . . . . . . . 9
SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
IBM Endorsement and Commitment (DB2) . . . . . . . . . . . . . . . . . . 9
Microsoft Commitment (SQL Server, ODBC, and ADO) . . . . . . . 9
Relational Foundation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
High-Level, English-Like Structure . . . . . . . . . . . . . . . . . . . . . . . . . 10
Interactive, Ad Hoc Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Programmatic Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Multiple Views of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Complete Database Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Dynamic Data Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Client/Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Enterprise Application Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

v
Copyright 2002 by The McGraw-Hill Companies, Inc. Click Here for Terms of Use.

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:06 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

vi SQL: The Complete Reference

Extensibility and Object Technology . . . . . . . . . . . . . . . . . . . . . . . . 12


Internet Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Java Integration (JDBC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Industry Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 A Quick Tour of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
A Simple Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Summarizing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Adding Data to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Deleting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Updating the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Protecting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3 SQL in Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
SQL and Database Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
A Brief History of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
The Early Years . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Early Relational Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
IBM Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Commercial Acceptance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The ANSI/ISO Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Other SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
ODBC and the SQL Access Group . . . . . . . . . . . . . . . . . . . . . . . . . . 34
SQL and Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
SQL and Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Centralized Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
File Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Client/Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Multitier Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
The Proliferation of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
SQL and IBM’s Unified Database Strategy . . . . . . . . . . . . . . . . . . . 42
SQL on Minicomputers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
SQL on UNIX-Based Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
SQL on Personal Computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
SQL and Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
SQL and Workgroup Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
SQL and Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
SQL and Distributed Internet Applications . . . . . . . . . . . . . . . . . . 48
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4 Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Early Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
File Management Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Hierarchical Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Network Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:07 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents vii

The Relational Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57


The Sample Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Primary Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Codd’s 12 Rules * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Part II
Retrieving Data
5 SQL Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Table Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Column Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Numeric Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Date and Time Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Symbolic Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Missing Data (NULL Values) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6 Simple Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
The SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
The SELECT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
The FROM Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Query Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Simple Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Calculated Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Selecting All Columns (SELECT *) . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Duplicate Rows (DISTINCT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Row Selection (WHERE Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
The Comparison Test (=, <>, <, <=, >, >=) . . . . . . . . . . . . . . . . . . . 111
The Range Test (BETWEEN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
The Set Membership Test (IN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
The Pattern Matching Test (LIKE) . . . . . . . . . . . . . . . . . . . . . . . . . . 120
The Null Value Test (IS NULL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Compound Search Conditions (AND, OR, and NOT) . . . . . . . . . . . . 124
Sorting Query Results (ORDER BY Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Rules for Single-Table Query Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Combining Query Results (UNION) * . . . . . . . . . . . . . . . . . . . . . . . . 131
Unions and Duplicate Rows * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:07 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

viii SQL: The Complete Reference

Unions and Sorting * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135


Multiple UNIONs* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

7 Multitable Queries (Joins) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139


A Two-Table Query Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Simple Joins (Equi-Joins) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Parent/Child Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Joins with Row Selection Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Multiple Matching Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Queries with Three or More Tables . . . . . . . . . . . . . . . . . . . . . . . . . 148
Other Equi-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Non-Equi-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
SQL Considerations for Multitable Queries . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Qualified Column Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
All-Column Selections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Self-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Table Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Multitable Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
The Structure of a Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Table Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Rules for Multitable Query Processing . . . . . . . . . . . . . . . . . . . . . . 164
Outer Joins * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Left and Right Outer Joins * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Outer Join Notation * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Joins and the SQL2 Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Inner Joins in SQL2 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Outer Joins in SQL2 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Cross Joins and Union Joins in SQL2 * . . . . . . . . . . . . . . . . . . . . . . . 180
Multitable Joins in SQL2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
8 Summary Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Column Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Computing a Column Total (SUM) . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Computing a Column Average (AVG) . . . . . . . . . . . . . . . . . . . . . . . 191
Finding Extreme Values (MIN and MAX) . . . . . . . . . . . . . . . . . . . . . 191
Counting Data Values (COUNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Column Functions in the Select List . . . . . . . . . . . . . . . . . . . . . . . . . 195
NULL Values and Column Functions . . . . . . . . . . . . . . . . . . . . . . . . 197
Duplicate Row Elimination (DISTINCT) . . . . . . . . . . . . . . . . . . . . . 199
Grouped Queries (GROUP BY Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Multiple Grouping Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Restrictions on Grouped Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
NULL Values in Grouping Columns . . . . . . . . . . . . . . . . . . . . . . . . . 209
Group Search Conditions (HAVING Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Restrictions on Group Search Conditions . . . . . . . . . . . . . . . . . . . . 214
NULL Values and Group Search Conditions . . . . . . . . . . . . . . . . . . 215
HAVING Without GROUP BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:07 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents ix

9 Subqueries and Query Expressions . . . . . . . . . . . . . . . . . . . . . 217


Using Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
What Is a Subquery? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Subqueries in the WHERE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Outer References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Subquery Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
The Subquery Comparison Test (=, <>, <, <=, >, >=) . . . . . . . . . . 223
The Set Membership Test (IN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
The Existence Test (EXISTS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Quantified Tests (ANY and ALL) * . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Subqueries and Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Nested Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Correlated Subqueries * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Subqueries in the HAVING Clause * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Subquery Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Advanced Queries in SQL2 * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Scalar-Valued Expressions (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Row-Valued Expressions (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Table-Valued Expressions (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Query Expressions (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
SQL Queries: A Final Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

Part III
Updating Data
10 Database Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Adding Data to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
The Single-Row INSERT Statement . . . . . . . . . . . . . . . . . . . . . . . . . 271
The Multirow INSERT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Bulk Load Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Deleting Data from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
The DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Deleting All Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
DELETE with Subquery * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Modifying Data in the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
The UPDATE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Updating All Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
UPDATE with Subquery * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
11 Data Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
What Is Data Integrity? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Required Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Simple Validity Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Column Check Constraints (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . 295
Domains (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Entity Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Other Uniqueness Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Uniqueness and NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

x SQL: The Complete Reference

Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299


Referential Integrity Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Delete and Update Rules * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Cascaded Deletes and Updates * . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Referential Cycles * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Foreign Keys and NULL Values * . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Advanced Constraint Capabilities (SQL2) . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
SQL2 Constraint Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Deferred Constraint Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Business Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
What Is a Trigger? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Triggers and Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Trigger Advantages and Disadvantages . . . . . . . . . . . . . . . . . . . . . 323
Triggers and the SQL Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
12 Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
What Is a Transaction? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
COMMIT and ROLLBACK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
The ANSI/ISO Transaction Model . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Other Transaction Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Transactions: Behind the Scenes * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Transactions and Multiuser Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
The Lost Update Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
The Uncommitted Data Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
The Inconsistent Data Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
The Phantom Insert Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Concurrent Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Locking * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Locking Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Shared and Exclusive Locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Deadlocks * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Advanced Locking Techniques * . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Versioning * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Versioning in Operation * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Versioning Advantages and Disadvantages * . . . . . . . . . . . . . . . . 360
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361

Part IV
Database Structure
13 Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
The Data Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Table Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Creating a Table (CREATE TABLE) . . . . . . . . . . . . . . . . . . . . . . . . . 369
Removing a Table (DROP TABLE) . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Changing a Table Definition (ALTER TABLE) . . . . . . . . . . . . . . . . 380

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents xi

Constraint Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384


Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Aliases and Synonyms (CREATE/DROP ALIAS) . . . . . . . . . . . . . . . . . . . . . . 386
Indexes (CREATE/DROP INDEX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Managing Other Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Single-Database Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Multidatabase Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Multilocation Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Databases on Multiple Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Database Structure and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . 401
SQL2 Catalogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
SQL2 Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
14 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
What Is a View? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
How the DBMS Handles Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Advantages of Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Disadvantages of Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Creating a View (CREATE VIEW) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Horizontal Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Vertical Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Row/Column Subset Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Grouped Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Joined Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Updating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
View Updates and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . 424
View Updates in Commercial SQL Products . . . . . . . . . . . . . . . . . 425
Checking View Updates (CHECK OPTION) . . . . . . . . . . . . . . . . . . . 425
Dropping a View (DROP VIEW) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Materialized Views * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
15 SQL Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
SQL Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
User-Ids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Security Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Views and SQL Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Granting Privileges (GRANT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Column Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Passing Privileges (GRANT OPTION) . . . . . . . . . . . . . . . . . . . . . . . . 449
Revoking Privileges (REVOKE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
REVOKE and the GRANT OPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
REVOKE and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . . 456
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:08 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

xii SQL: The Complete Reference

16 The System Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459


What Is the System Catalog? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
The Catalog and Query Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
The Catalog and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . 461
Catalog Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Table Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Column Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
View Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Relationship Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
User Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Privileges Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
The SQL2 Information Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Other Catalog Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487

Part V
Programming with SQL
17 Embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Programmatic SQL Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
DBMS Statement Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Embedded SQL Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
Developing an Embedded SQL Program . . . . . . . . . . . . . . . . . . . . 496
Running an Embedded SQL Program . . . . . . . . . . . . . . . . . . . . . . . 500
Simple Embedded SQL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Declaring Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Using Host Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
Data Retrieval in Embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Single-Row Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Multirow Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
Cursor-Based Deletes and Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Cursors and Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
18 Dynamic SQL * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Limitations of Static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Dynamic SQL Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Dynamic Statement Execution (EXECUTE IMMEDIATE) . . . . . . . . . . . . . . . . 551
Two-Step Dynamic Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
The PREPARE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
The EXECUTE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
Dynamic Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
The DESCRIBE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
The DECLARE CURSOR Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 574
The Dynamic OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
The Dynamic FETCH Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
The Dynamic CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents xiii

Dynamic SQL Dialects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579


Dynamic SQL in Oracle * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Dynamic SQL and the SQL2 Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Basic Dynamic SQL2 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
SQL2 and the SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
SQL2 and Dynamic SQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
19 SQL APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
API Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
The dblib API (SQL Server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
Basic SQL Server Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
SQL Server Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Positioned Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
Dynamic Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
ODBC and the SQL/CLI Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
The Call-Level Interface Standardization . . . . . . . . . . . . . . . . . . . . 622
CLI Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
CLI Statement Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
CLI Errors and Diagnostic Information . . . . . . . . . . . . . . . . . . . . . . 651
CLI Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
CLI Information Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
The ODBC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
The Structure of ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
ODBC and DBMS Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
ODBC Catalog Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
Extended ODBC Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
The Oracle Call Interface (OCI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
OCI Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Oracle Server Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
Statement Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
Query Results Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
Descriptor Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
Transaction Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Java Database Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
JDBC History and Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
JDBC Implementations and Driver Types . . . . . . . . . . . . . . . . . . . . 672
The JDBC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697

Part VI
SQL Today and Tomorrow
20 Database Processing and Stored Procedures . . . . . . . . . . . . . 701
Stored Procedure Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
A Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Using Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
Creating a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
Calling a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

xiv SQL: The Complete Reference

Stored Procedure Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710


Statement Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713
Returning a Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Returning Values via Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
Conditional Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
Repeated Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
Other Flow-of-Control Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Cursor-Based Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
Handling Error Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
Advantages of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
Stored Procedure Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
System-Defined Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
External Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736
Advantages and Disadvantages of Triggers . . . . . . . . . . . . . . . . . . 737
Triggers in Transact-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738
Triggers in Informix SPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
Triggers in Oracle PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Other Trigger Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Stored Procedures, Triggers, and the SQL Standard . . . . . . . . . . . . . . . . . . . 744
The SQL/PSM Stored Procedures Standard . . . . . . . . . . . . . . . . . . 745
Trigger Standards in SQL:1999 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
21 SQL and Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
Data Warehousing Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 760
Components of a Data Warehouse . . . . . . . . . . . . . . . . . . . . . . . . . . 762
The Evolution of Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . 763
Database Architecture for Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
Fact Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
Star Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
Multilevel Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768
SQL Extensions for Data Warehousing . . . . . . . . . . . . . . . . . . . . . . 770
Warehouse Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
Load Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
22 SQL and Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . 775
SQL and Web Sites: Early Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . 776
Application Servers and Three-Tier Web Site Architectures . . . . . . . . . . . . 777
Database Access from Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
EJB Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
Session Bean Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
Entity Bean Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785
EJB 2.0 Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
Application Server Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 790
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:09 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents xv

23 SQL Networking and Distributed Databases . . . . . . . . . . . . . 795


The Challenge of Distributed Data Management . . . . . . . . . . . . . . . . . . . . . 796
Distributing Data: Practical Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
Remote Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
Remote Data Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Table Extracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
Table Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
Updateable Replicas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
Replication Trade-Offs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
Typical Replication Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . 814
Distributed Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
Remote Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Remote Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820
Distributed Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821
Distributed Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822
The Two-Phase Commit Protocol * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824
Network Applications and Database Architecture . . . . . . . . . . . . . . . . . . . . 827
Client/Server Applications and Database Architecture . . . . . . . . 828
Client/Server Applications with Stored Procedures . . . . . . . . . . . 829
Enterprise Applications and Data Caching . . . . . . . . . . . . . . . . . . . 830
High-Volume Internet Data Management . . . . . . . . . . . . . . . . . . . 832
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832
24 SQL and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835
Object-Oriented Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836
Object-Oriented Database Characteristics . . . . . . . . . . . . . . . . . . . . 837
Pros and Cons of Object-Oriented Databases . . . . . . . . . . . . . . . . . 838
Objects and the Database Market . . . . . . . . . . . . . . . . . . . . . . . . . . . 839
Object-Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
Large Object Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841
BLOBs in the Relational Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
Specialized BLOB Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
Abstract (Structured) Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
Defining Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
Manipulating Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . 850
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
Table Inheritance: Implementing Object Classes . . . . . . . . . . . . . . 854
Sets, Arrays, and Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
Defining Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
Querying Collection Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863
Manipulating Collection Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864
Collections and Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . 865
User-Defined Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 868
Methods and Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
Object Support in the SQL:1999 Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

xvi SQL: The Complete Reference

25 SQL and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875


What Is XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876
XML Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877
XML for Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
XML and SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
Elements vs. Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882
Using XML with Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885
XML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
XML Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888
XML Data Exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890
XML Storage and Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890
XML and Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895
Document Type Definitions (DTDs) . . . . . . . . . . . . . . . . . . . . . . . . 897
XML Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
XML and Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906
XQuery Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
Query Processing in XQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
XML Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
26 The Future of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
Database Market Trends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
Enterprise Database Market Maturity . . . . . . . . . . . . . . . . . . . . . . . 915
Market Diversity and Segmentation . . . . . . . . . . . . . . . . . . . . . . . . 916
Packaged Enterprise Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 917
Hardware Performance Gains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
Database Server Appliances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919
Benchmark Wars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 920
SQL Standardization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
SQL in the Next Decade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 924
Distributed Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
Massive Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
Ultra-High-Performance Databases . . . . . . . . . . . . . . . . . . . . . . . . . 926
Internet and Network Services Integration . . . . . . . . . . . . . . . . . . . 927
Embedded Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928
Object Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930

Part VII
Appendixes
A The Sample Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
B Database Vendor Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941
A2i, Inc. (www.a2i.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
Arbor Software (www.hyperion.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
Birdstep Technology (www.birdstep.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
Computer Associates (www.cai.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 944
Computer Corporation of America (www.cca-int.com) . . . . . . . . . . . . . . . . 945
Empress Software (www.empress.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Contents xvii

eXcelon (www.exln.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946


Gupta Technologies (www.guptaworldwide.com) . . . . . . . . . . . . . . . . . . . . 947
Hewlett Packard (www.hp.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
IBM Corporation (www.ibm.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
Informix Software (See IBM Corporation) . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
Microsoft Corporation (www.microsoft.com) . . . . . . . . . . . . . . . . . . . . . . . . 950
MySQL AB (www.mysql.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 951
Objectivity (www.objectivity.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 951
Oracle Corporation (www.oracle.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952
Persistence Software (www.persistence.com) . . . . . . . . . . . . . . . . . . . . . . . . 953
Pervasive Software (www.pervasive.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
PointBase (www.pointbase.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
PostgreSQL (www.postgresql.org) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
Quadbase Systems (www.quadbase.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
Red Brick Systems (See IBM Corporation) . . . . . . . . . . . . . . . . . . . . . . . . . . . 956
Sybase, Inc. (www.sybase.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
TimesTen Performance Software (www.timesten.com) . . . . . . . . . . . . . . . . 958
Versant Corporation (www.versant.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
C SQL Syntax Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
Data Definition Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
Basic Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
Transaction Processing Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965
Cursor-Based Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965
Query Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
Statement Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
Simple Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
D SQL Call-Level Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971
CLI Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974
General Handle Management Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974
SQL Environment Management Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
SQL Connection Management Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
SQL Statement Management Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 977
SQL Statement Execution Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
Query Results Processing Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
Query Results Description Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980
Query Results Descriptor Management Routines . . . . . . . . . . . . . . . . . . . . . . 980
Deferred Dynamic Parameter Processing Routines . . . . . . . . . . . . . . . . . . . . . 982
Error, Status, and Diagnostic Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982
CLI Implementation Information Routines . . . . . . . . . . . . . . . . . . . . . . . . . . 983
CLI Parameter Value Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
E SQL Information Schema Standard . . . . . . . . . . . . . . . . . . . . . 991
The SCHEMATA View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993
The TABLES View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994
The COLUMNS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994
The VIEWS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 996

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:10 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

xviii SQL: The Complete Reference

The VIEW_TABLE_USAGE View . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997


The VIEW_COLUMN_USAGE View . . . . . . . . . . . . . . . . . . . . . . . . . . . 997
The TABLE_CONSTRAINTS View . . . . . . . . . . . . . . . . . . . . . . . . . . . 998
The REFERENTIAL_CONSTRAINTS View . . . . . . . . . . . . . . . . . . . 999
The CHECK_CONSTRAINTS View . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000
The KEY_COLUMN_USAGE View . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000
The ASSERTIONS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1001
The CONSTRAINT_TABLE_USAGE View . . . . . . . . . . . . . . . . . . . . . 1001
The CONSTRAINT_COLUMN_USAGE View . . . . . . . . . . . . . . . . . . . 1002
The TABLE_PRIVILEGES View . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003
The COLUMN_PRIVILEGES View . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003
The USAGE_PRIVILEGES View . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1004
The DOMAINS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005
The DOMAIN_CONSTRAINTS View . . . . . . . . . . . . . . . . . . . . . . . . . 1006
The DOMAIN_COLUMN_USAGE View . . . . . . . . . . . . . . . . . . . . . . . . 1007
The CHARACTER_SETS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008
The COLLATIONS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
The TRANSLATIONS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
The SQL_LANGUAGES View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010
F CD-ROM Installation Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013
Installing the SQL DBMS Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1014
Microsoft SQL Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015
Hardware and Software Requirements . . . . . . . . . . . . . . . . . . . . . . 1016
Installation Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016
SQL Server 2000 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
Starting SQL Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
Uninstalling SQL Server 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
IBM DB2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
Hardware and Software Requirements . . . . . . . . . . . . . . . . . . . . . . 1019
Installation Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1019
DB2 Enterprise Edition Installation . . . . . . . . . . . . . . . . . . . . . . . . . 1019
Starting DB2 Enterprise Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
Uninstalling DB2 Enterprise Edition . . . . . . . . . . . . . . . . . . . . . . . . 1021
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
Hardware and Software Requirements . . . . . . . . . . . . . . . . . . . . . . 1021
Installation Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022
MySQL Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022
Starting MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
Uninstalling MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
Downloading the Oracle DBMS Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter
FM:xix

Acknowledgments
pecial thanks to Matan Arazi for once again doing an exceptional job of assembling

S the bonus CD-ROM, pulling off another miracle by squeezing three DBMS products
onto a single CD, and doing so against impossibly tight deadlines.
Thanks also to the team at Osborne, including Jane Brownlow, Jennifer Malnick,
Martin Przybyla, Greg Guntle, and Chrisa Hotchkiss.

xix
Copyright 2002 by The McGraw-Hill Companies, Inc. Click Here for Terms of Use.

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:11 PM
This page intentionally left blank.
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter
FM:xxi

Introduction
QL: The Complete Reference, Second Edition provides a comprehensive, in-depth

S treatment of the SQL language for both technical and nontechnical users,
programmers, data processing professionals, and managers who want to
understand the impact of SQL in today’s computer industry. This book offers a
conceptual framework for understanding and using SQL, describes the history of
SQL and SQL standards, and explains the role of SQL in various computer industry
segments, from enterprise data processing to data warehousing to web site architectures.
This new edition contains new chapters specially focused on the role of SQL in
application server architectures, and the integration of SQL with XML and other
object-based technologies.
This book will show you, step-by-step, how to use SQL features, with many
illustrations and realistic examples to clarify SQL concepts. The book also compares
SQL products from leading DBMS vendors—describing their advantages benefits and
trade-offs—to help you select the right product for your application. The accompanying
CD-ROM contains actual trial versions of three of the leading brands of SQL DBMS, plus
instructions on how to download a trial version of a fourth version, so you can try them
for yourself and gain actual experience in using the major DBMS products from Oracle,
Microsoft, and IBM, and the popular open source DBMS MySQL.

xxi
Copyright 2002 by The McGraw-Hill Companies, Inc. Click Here for Terms of Use.

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

xxii SQL: The Complete Reference

In some of the chapters, the subject matter is explored at two different levels—a
fundamental description of the topic, and an advanced discussion intended for computer
professionals who need to understand some of the internals behind SQL. The more
advanced information is covered in sections marked with an asterisk (*). You do not
need to read these sections to obtain an understanding of what SQL is and what it does.

How This Book Is Organized


The book is divided into six parts that cover various aspects of the SQL language:

■ Part One, “An Overview of SQL,” provides an introduction to SQL and a


market perspective of its role as a database language. Its four chapters describe
the history of SQL, the evolution of SQL standards, and how SQL relates to
the relational data model and to earlier database technologies. Part One also
contains a quick tour of SQL that briefly illustrates its most important features
and provides you with an overview of the entire language early in the book.
■ Part Two, “Retrieving Data,” describes the features of SQL that allow you
to perform database queries. The first chapter in this part describes the basic
structure of the SQL language. The next four chapters start with the simplest
SQL queries and progressively build to more complex queries, including
multitable queries, summary queries, and queries that use subqueries.
■ Part Three, “Updating Data,” shows how you can use SQL to add new data
to a database, delete data from a database, and modify existing database data.
It also describes the database integrity issues that arise when data is updated,
and how SQL addresses these issues. The last of the three chapters in this
part discusses the SQL transaction concept and SQL support for multiuser
transaction processing.
■ Part Four, “Database Structure,” deals with creating and administering a
SQL-based database. Its four chapters tell you how to create the tables, views,
and indexes that form the structure of a relational database. It also describes
the SQL security scheme that prevents unauthorized access to data, and the
SQL system catalog that describes the structure of a database. This part also
discusses the significant differences between the database structures supported
by various SQL-based DBMS products.
■ Part Five, “Programming with SQL,” describes how application programs
use SQL for database access. It discusses the embedded SQL specified by the
ANSI standard and used by IBM, Oracle, Ingres, Informix, and many other
SQL-based DBMS products. It also describes the dynamic SQL interface that
is used to build general-purpose database tables, such as report writers and
database browsing programs. Finally, this part describes the popular SQL
APIs, including ODBC, the ISO-standard Call-Level Interface, and JDBC, the

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:11 PM
Color profile: Generic CMYK printer profile
Composite Default screen Complete Reference / SQL: TCR / Groff, Weinberg / 222559-9 / Front Matter

Introduction xxiii

standard call-level interface for Java, as well as proprietary call-level interfaces


such as Oracle’s OCI API.
■ Part Six, “SQL Today and Tomorrow,” examines the use of SQL in several
of today’s “hottest” application areas, and the current state of SQL-based
DBMS products. Two chapters describe the use of SQL stored procedures
and triggers for online transaction processing, and the contrasting use of SQL
for data warehousing. Four additional chapters describe SQL-based distributed
databases, the influence of object technologies on SQL, and the integration of
SQL with XML technologies. Finally, the last chapter explores the future of SQL
and some of the most important trends in SQL-based data management.

Conventions Used In This Book


SQL: The Complete Reference, Second Edition describes the SQL features and functions
available in the most popular SQL-based DBMS products and those described in the
ANSI/ISO SQL standards. Whenever possible, the SQL statement syntax described in
this book and used in the examples applies to all dialects of SQL. When the dialects
differ, the differences are pointed out in the text, and the examples follow the most
common practice. In these cases, you may have to modify the SQL statements in the
examples slightly to suit your particular brand of DBMS.
Throughout the book, technical terms appear in italics the first time they are used
and defined. SQL language elements, including SQL keywords, table, and column
names, and sample SQL statements, appear in an UPPERCASE MONOSPACE font. SQL
API function names appear in a lowercase monospace font. Program listings also
appear in monospace font, and use the normal case conventions for the particular
programming language (uppercase for COBOL and FORTRAN, lowercase for C and
Java). Note that these conventions are used solely to improve readability; most SQL
implementations will accept either uppercase or lowercase statements. Many of the
SQL examples include query results, which appear immediately following the SQL
statement as they would in an interactive SQL session. In some cases, long query
results are truncated after a few rows; this is indicated by a vertical ellipsis (…)
following the last row of query results.

Why This Book Is For You


SQL: The Complete Reference, Second Edition is the right book for anyone who wants to
understand and learn SQL, including database users, data processing professionals and
architects, programmers, students, and managers. It describes—in simple, understandable
language liberally illustrated with figures and examples—what SQL is, why it is important,
and how you use it. This book is not specific to one particular brand or dialect of SQL.
Rather, it describes the standard, central core of the SQL language and then goes on

P:\010Comp\CompRef8\559-9\fm.vp
Friday, July 26, 2002 2:25:12 PM
Another Random Document on
Scribd Without Any Related Topics
Mr. Coleman. Yes.
Miss Waterman. Outside the Passport Office?
Mr. Coleman. Yes; I am just asking you for the record.
Miss Waterman. I know. But you mentioned—such as who?
Mr. Coleman. Did anyone call you up and say, "Miss Waterman,
this is the way you have to resolve this case"?
Miss Waterman. Oh, no. Oh, no.
Mr. Coleman. And you made the decisions you made based upon
the record and your judgment as to what you thought the law was
and what the facts were?
Miss Waterman. Certainly.
Mr. Dulles. Did you consult anyone in connection with reaching
that decision in the Oswald case?
Miss Waterman. Well, Mr. Dulles, in preparing this
correspondence, as I have told you, the correspondence was
prepared for the signature of my superiors, and if they didn't agree
with what I wrote, that was all right with me. But that was my
impression, and I believed there had been discussion among persons
in our immediate office. And while——
Mr. Dulles. Your decision, then, is not final. It is subject to review
by your superiors in matters of this kind?
Miss Waterman. That is right.
But in no event—I don't know of any—as I say, my connection
with the case closed, and I never heard in the press or any other
place that indicated that Oswald expatriated himself and that he
wasn't entitled to a passport.
Mr. Coleman. Your decision wasn't in any way influenced by the
fact that Miss James told you that this was a decision that would
have to be made or anything like that?
Miss Waterman. Certainly not. They have absolutely nothing to do
with citizenship—nothing.
Mr. Coleman. I have no further questions, Mr. Chairman.
Mr. Dulles. Off the record.
(Discussion off the record.)
Mr. Coleman. Mr. Chairman, before we close the testimony of Miss
Waterman, I would like to move for the admission of Commission
Exhibits No. 957 through Commission Exhibit No. 983, which were
the documents that we marked.
Mr. Dulles. They shall be admitted.
(The documents heretofore marked for identification as
Commission Exhibits Nos. 957–983, were received in evidence.)
Mr. Coleman. I would like to thank Miss Waterman for coming in.
Mr. Dulles. We thank you very much, Miss Waterman.
(Whereupon, at 12:50 p.m., the President's Commission
recessed.)
Afternoon Session

TESTIMONY OF THE HON. DEAN


RUSK, SECRETARY OF STATE
The President's Commission reconvened at 3:30 p.m.
The Chairman. Mr. Secretary Dean Rusk, we wanted to ask you a
few questions about this matter in any particular detail you wanted
to answer. Mr. Rankin would you inform the Secretary the areas we
intend to cover before we ask the questions.
Mr. Rankin. Mr. Chief Justice, I think the particular area that we
would be interested in with the Secretary is just as to whether, or his
knowledge of whether there was any foreign political interest in the
assassination of President Kennedy?
We have been getting the information in regard to other matters
concerning the State Department from other of his associates and
colleagues and employees of the Department, and we are going to
complete that and it has been helpful to us and I think we can rather
limit the inquiry to that area.
The Chairman. Yes; very well.
Mr. Secretary, would you rise and be sworn, please. Do you
solemnly swear the testimony you are about to give before this
Commission shall be the truth, the whole truth, and nothing but the
truth, so help you God?
Secretary Rusk. I do.
The Chairman. Will you be seated, please, and Mr. Rankin will ask
you the questions, Mr. Secretary.
Secretary Rusk. Mr. Chief Justice, may I ask one question?
The Chairman. Yes, indeed.
Secretary Rusk. I would like to be just as helpful as possible to
the Commission. I am not quite clear of testimony in terms of future
publication. There may be certain points that arise where it might be
helpful to the Commission for me to comment on certain points but
there—it would be a very grave difficulty about publication, so I
wonder what the Commission's view on that is.
The Chairman. Well, Mr. Secretary, our purpose is to have
available for the public all of the evidence that is given here. If there
is any phase of it that you think might jeopardize the security of the
Nation, have no hesitation in asking us to go off the record for a
moment, and you can tell us what you wish.
Secretary Rusk. Thank you, sir, I am at your disposal.
Mr. Dulles. Mr. Chief Justice, could I make a suggestion in that
connection?
The Chairman. Yes.
Mr. Dulles. Would it be feasible to have a discussion here of the
points that are vital from the point of view of our record, and so
forth, and maybe a little informal conversation afterward to cover
the other points.
The Chairman. We will have a recess for a few moments then.
Mr. Dulles. I thought between the two wouldn't that be easier
than put the two together.
(Discussion off the record.)
The Chairman. Back on the record.
Mr. Rankin. Mr. Secretary, will you give us your name and
address, please?
Secretary Rusk. Dean Rusk, 4980 Quebec Street, Washington,
D.C.
Mr. Rankin. And you are the Secretary of State for the United
States?
Secretary Rusk. That is correct.
Mr. Rankin. You have occupied that position for some time?
Secretary Rusk. Since January 22, 1961.
Mr. Rankin. In that position you have become familiar with our
foreign relations and the attitude and interest in some degree of
other countries that we deal with?
Secretary Rusk. Yes; within the limitations of the possibilities, it is
at least my task to be as familiar as possible with those things.
Mr. Rankin. In your opinion, was there any substantial interest or
interests of the Soviet Union which would have been advanced by
the assassination of President Kennedy?
Secretary Rusk. I would first have to say on a question of that
sort that it is important to follow the evidence. It is very difficult to
look into the minds of someone else, and know what is in someone
else's mind.
I have seen no evidence that would indicate to me that the
Soviet Union considered that it had an interest in the removal of
President Kennedy or that it was in any way involved in the removal
of President Kennedy. If I may elaborate just a moment.
Mr. Rankin. If you will, please.
Secretary Rusk. As the Commission may remember, I was with
several colleagues in a plane on the way to Japan at the time the
assassination occurred. When we got the news we immediately
turned back. After my mind was able to grasp the fact that this
event had in fact occurred, which was the first necessity, and not an
easy one, I then, on the plane, began to go over the dozens and
dozens of implications and ramifications of this event as it affects our
foreign relations all over the world.
I landed briefly in Hawaii on the way back to Washington, and
gave some instructions to the Department about a number of these
matters, and learned what the Department was already doing. But
one of the great questions in my mind at that time was just that
question, could some foreign government somehow be involved in
such an episode.
I realized that were this so this would raise the gravest issues of
war and peace, but that nevertheless it was important to try to get
at the truth—to the answer to that question—wherever that truth
might lead; and so when I got back to Washington I put myself
immediately in touch with the processes of inquiry on that point, and
as Secretary of State had the deepest possible interest in what the
truthful answer to those questions would be, because it would be
hard to think of anything more pregnant for our foreign relations
than the correct answer to that question.
I have not seen or heard of any scrap of evidence indicating that
the Soviet Union had any desire to eliminate President Kennedy nor
in any way participated in any such event.
Now, standing back and trying to look at that question
objectively despite the ideological differences between our two great
systems, I can't see how it could be to the interest of the Soviet
Union to make any such effort.
Since I have become Secretary of State I have seen no evidence
of any policy of assassination of leaders of the free world on the part
of the Soviets, and our intelligence community has not been able to
furnish any evidence pointing in that direction.
I am sure that I would have known about such bits of evidence
had they existed but I also made inquiry myself to see whether there
was such evidence, and received a negative reply.
I do think that the Soviet Union, again objectively considered,
has an interest in the correctness of state relations. This would be
particularly true among the great powers, with which the major
interests of the Soviet Union are directly engaged.
Mr. Rankin. Could you expand on that a little bit so that others
than those who deal in that area might understand fully what you
mean?
Secretary Rusk. Yes; I think that although there are grave
differences between the Communist world and the free world,
between the Soviet Union and other major powers, that even from
their point of view there needs to be some shape and form to
international relations, that it is not in their interest to have this
world structure dissolve into complete anarchy, that great states and
particularly nuclear powers have to be in a position to deal with each
other, to transact business with each other, to try to meet problems
with each other, and that requires the maintenance of correct
relations and access to the leadership on all sides.
I think also that although there had been grave differences
between Chairman Khrushchev and President Kennedy, I think there
were evidences of a certain mutual respect that had developed over
some of the experiences, both good and bad, through which these
two men had lived.
I think both of them were aware of the fact that any Chairman
of the Soviet Union and any President of the United States
necessarily bear somewhat special responsibility for the general
peace of the world.
Indeed without exaggeration, one could almost say the existence
of the Northern Hemisphere in this nuclear age.
So that it would be an act of rashness and madness for Soviet
leaders to undertake such an action as an active policy. Because
everything would have been put in jeopardy or at stake in
connection with such an act.
It has not been our impression that madness has characterized
the actions of the Soviet leadership in recent years.
I think also that it is relevant that people behind the Iron
Curtain, including people in the Soviet Union and including officials in
the Soviet Union, seemed to be deeply affected by the death of
President Kennedy.
Their reactions were prompt, and I think genuine, of regret and
sorrow. Mr. Khrushchev was the first to come to the Embassy to sign
the book of condolences. There were tears in the streets of Moscow.
Moscow Radio spent a great deal of attention to these matters.
Now they did come to premature conclusions, in my judgment,
about what this event was and what it meant in terms of who might
have been responsible for it—and ideological effect has crept into
that.
But I had the impression that the regret was genuine and that
the ordinary Soviet citizen joined with ordinary people in other parts
of the world in feeling the loss of the President in a very genuine
sense.
Mr. Rankin. There has been some suggestion that possibly the
leadership of the Soviet Union would not have been politically
interested in the death of the President but possibly a distant wing
of the Party might have been so involved.
Can you give us any light on that, Mr. Secretary.
The Chairman. By suggestion you mean rumor?
Mr. Rankin. In the newspapers, and things of that kind, rumor.
Secretary Rusk. I haven't been able to put a rational structure
behind that possibility. If there are dissident elements their primary
problem is within the Soviet Union.
If these dissident elements were aiming to change the present
Government of the Soviet Union or its leadership or to return to an
early range of policy by the elimination of present leadership or
seizure of control, I don't quite see how the elimination of the
President of the United States could contribute to that purpose.
I would also suppose that in their kind of system such elements
would be under pretty close supervision and surveillance and they
would have limited opportunities for the kind of action that would be
organized in a way in this direction, although that is a matter of
some speculation.
But, I would doubt very much that such dissident elements
would have a motive or very much of an opportunity. Again, I have
seen no evidence pointing in that direction.
Mr. Rankin. How could you tell us in regard to Cuba in the same
general way, your opinion and knowledge of any information or
credible evidence?
Secretary Rusk. Well, I would again repeat that the overriding
consideration is to make every possible effort to find evidence and
follow the evidence to wherever it leads.
I think it is, at least for me, more difficult to try to enter into the
minds of the present leadership in Cuba than, perhaps, even of the
present leadership of the Soviet Union. We have had very few
contacts, as the Commission knows, with the present Government of
Cuba.
But again, I have seen no evidence that seems to point in that
direction.
There were some exchanges, with which the Commission is
familiar, that seemed to be—seemed to come to another conclusion.
But I would think that objective considerations would mean that it
would be even greater madness for Castro or his government to be
involved in any such enterprise than almost for anyone else, because
literally the issue of war and peace would mean the issue of the
existence of his regime and perhaps of his country might have been
involved in that question.
We were under the impression that there was very considerable
concern in Cuba as to whether they would be held responsible and
what the effect of that might be on their own position and their own
safety.
But I have seen no evidence that points to involvement by them,
and I don't see objective facts which would seem to make it in their
interests to remove Mr. Kennedy.
You see, this embarks upon, in any event it would embark upon,
an unpredictable trail for them to go down this path, but I would
think again the Commission would wish to examine the evidence as
it has been doing with meticulous care and follow the evidence in
these matters.
Mr. Rankin. After the assassination, did you have direct
communications with Ambassador Thomas Mann while he was still
Ambassador at Mexico?
Secretary Rusk. Yes; we had a number of exchanges with
Ambassador Mann connected with the presence in Mexico of Mr.
Oswald.
I say those messages, and over a period of some days had daily
consultations about them with our Deputy Under Secretary for
Political Affairs, Mr. U. Alexis Johnson. Mr. Johnson is my principal
representative in our dealings with the various intelligence and
security agencies of the government and with the Pentagon, and he
has an office very near mine on the seventh floor of the Department
of State.
These exchanges raised questions of the most far-reaching
character involving the possibility of the implications of another
government, and so I had a very deep personal interest in that at
the time.
Our principal concern was to be sure that the FBI and the CIA
who were the principal agencies investigating this matter would have
every possible facility at their disposal, and would—and that our
Ambassador would be given the fullest support from us in facilitating
the investigation at the Mexican end.
So I was for a period, until this particular trail ran its course,
very much involved in those exchanges.
Mr. Rankin. Do you have any commentary that you want to make
about those exchanges other than what you have given us?
Secretary Rusk. I think not, sir. I think that the materials, the
information developed in those exchanges are before the
Commission, and I believe the Commission has had a chance to
inquire into them both as I understand both here and in Mexico with
the appropriate agencies and I would think that the Commission's
conclusions on that would be more valuable than mine because I
have not put together all the pieces to draw finished conclusions
from them.
Mr. Rankin. One of the Commissioners saw a newspaper story
shortly after the assassination saying "The Voice of America beaming
its message into Russia immediately blamed the reactionary
rightwing movements after Kennedy's death."
Do you know anything about that matter or what the source of it
might have been?
Secretary Rusk. No; I have not anticipated that question so that I
could have a chance to investigate it, but I will, if I may, Mr. Chief
Justice, file a report with the Commission on that point.
I can say now that there was never any policy guidance from the
Department of State or from the leadership of the Voice of America
suggesting that any broadcasters take that line.
It is possible, and this is purely speculative at the moment, that
the Voice of America in repeating a great many news accounts, as it
frequently does in its overseas broadcasts, may have repeated some
news accounts from this country, among which might have been a
story to that effect from one source or another, but I would like if I
may, sir, an opportunity to investigate that point and make a report
to the Commission.
The Chairman. You may do that, Mr. Secretary.
Representative Ford. May I ask a question? Have we received in
the Commission all of the Voice of America broadcasts that were
made over a period of 2 to 7 days involved in this incident?
Mr. Rankin. I don't know of any.
Representative Ford. I think the Commission ought to have them
for our own analysis as well as the analysis of the Secretary of State.
Mr. Rankin. Is that under your jurisdiction?
Secretary Rusk. Yes; indeed I could provide that.
Mr. Rankin. If you will, please.
Secretary Rusk. The Commission might also be interested in
either digests or the fuller materials on world reactions to the
President's assassination.
I have here, for example, a daily summary of the 26th of
November 1963, on foreign radio and press reaction which gives
some interesting treatment about this behind the Iron Curtain.
I would be happy to furnish the Commission with any material of
that sort which you might wish.
Mr. Rankin. We would appreciate having that.
The Chairman. Very well, thank you, Mr. Secretary.
Representative Ford. Would that include the Voice of Moscow or
whatever they call it over there?
Secretary Rusk. Yes, sir.
Representative Ford. From the outset of the events that took
place?
Secretary Rusk. Yes, sir; you might just wish to look at the first
two or three paragraphs here to get a sample of the kind of
summary that that involves.
Mr. Dulles. Was that prepared in the Department or by the
Foreign Broadcast Information Service?
Secretary Rusk. This particular one is from the Foreign Broadcast
Information Service. We also have another one. We also have
another one from within the Department which is also available in
terms.
Representative Ford. I think it would be useful to have both for a
period of about a week or so. I realize this is a summary covering
several days. I think I saw that at the time.
Mr. Rankin. There was another statement in the paper apparently
purporting to be official that one of the Commissioners asked me to
ask about and that was the Washington Post, Sunday, November 24,
1963, which was quoted by the Commissioner as, "Today in
Washington State Department officials said they have no evidence
indicating involvement of any foreign power in the assassination."
Do you know anything about that or can you give us any
information?
Secretary Rusk. That was the view which we took at the time in
consultation with the investigative agencies. We did not then have
evidence of that sort nor do we now, and the implications of
suggesting evidence in the absence of evidence would have been
enormous.
Representative Ford. I don't understand that.
Secretary Rusk. Well, for us to leave the impression that we had
evidence that we could not describe or discuss, when in fact we
didn't have the evidence on a matter of such overriding importance
could have created a very dangerous situation in terms of——
Representative Ford. Wouldn't it have been just as effective to
say no comment?
Secretary Rusk. Well, unfortunately, under the practices of the
press, no comment would have been taken to confirm that there was
evidence. I mean, that would have been the interpretation that
many would have put upon no comment.
But, Mr. Ford, I think the key thing is that at the time that
statement was made we did not have such evidence. I mean, this
was a factual statement at that time.
Representative Ford. But, at that time, this was 2 days after the
assassination, you really didn't have much time to evaluate all of the
evidence.
Secretary Rusk. Well, that is correct. But if the evidence or the
known facts had changed certainly that type of statement would
have changed.
In other words, such statements are based upon the situation as
known at the time the statements are made.
Representative Ford. This statement then appeared in the
Sunday morning, November 24 issue or edition of the Washington
Post. That was a statement issued certainly on the 23d of November
because it had to be in order to get in the Sunday edition of the
Post. So, that is 24 hours after the assassination.
Secretary Rusk. That is correct, sir, and this statement was made
on the basis of such information as was available to us in the first 24
hours.
Mr. Rankin. I was also asked to inquire whether that was an
official statement if under your responsibility or if you could tell me
who would be responsible for it?
Secretary Rusk. Well, I would have to check the actual source of
the statement. But I would have no present doubt that it was an
officer of the Department who was authorized to make that and for
which I would be fully responsible.
Mr. Rankin. That is all I have.
Mr. Dulles. Could I ask a question in connection with that?
The Chairman. Mr. Dulles.
Mr. Dulles. There was some evidence presented here quite
recently when the district attorney of Dallas was here with regard to
a message from Washington, from the White House to the attorney
general of Texas, who was also here the other day before the
Commission, on this point: A rumor had reached Washington that in
preparing the indictment there, they were going to put in some
reference to an international conspiracy. As a matter of fact, when
that was run down it was not a correct rumor. But when that
reached Washington, the reaction was rather strong and I think
entirely understandable, and word went back to Dallas from high
quarters that that should not, hoped that that would not be included
in the legal proceedings and papers that were filed in connection
with the assassination of the President and charging——
Mr. Rankin. Unless there was evidence to support it.
Mr. Dulles. Unless there was evidence to support it. And the
district attorney, who was here, testified that he had never
considered adding that into it, putting that in the proceedings
because if you put it in you had to prove it, and it is not necessary at
all. All you need to do is allege a murder with intent, and so forth,
and so on. So that that was all pretty well cleared up.
Mr. Dulles. Did that ever reach your attention, did you know
anything about that?
Secretary Rusk. I don't personally recall that particular message.
I do recall——
Mr. Dulles. That took place, I think before you got back, because
that took place on the evening of the 22d.
Secretary Rusk. I didn't arrive until——
Mr. Dulles. You didn't get back until the 23d?
Secretary Rusk. Until the early morning of the 23d.
Mr. Dulles. Yes.
Secretary Rusk. I do recall being concerned if several different
authorities and agencies undertook investigations that would cut
across each other's bow or make it difficult to elicit the cooperation
of people outside the United States whose cooperation we might
need in matters of that sort, I felt myself at that time there ought to
be a complete and absolutely thorough investigation by the most
responsible authorities and I was glad to see that brought into some
order at the time but I don't remember the particular message you
are talking about.
Representative Ford. Could you check to see if somebody in the
Department of State made such a call or made such a contact?
Secretary Rusk. Yes; I will be be glad to.
Representative Ford. And if so so report it for the proceedings?
Secretary Rusk. Yes, indeed; I will be glad to.
Mr. Chayes. I may be able to supply some information to the
Commission on this point because during the night of the 22d when
we were examining the data in my office, the files, I did receive a
call from Mr. Katzenbach who said that they had heard at the Justice
Department, that there was a possibility that this kind of an element
would get into the indictment, and said that—I can't remember the
exact words that he used—but he conveyed to me that he regarded
this as not very good, in the absence of evidence to support it, and
said that he was seeking to have Mr. Saunders, who is the U.S.
attorney in Dallas, admitted to the councils of the State officials
there so that they could discuss these matters as time went on. And
that he would try to, I don't know exactly again what he said, but
that he would try to see that in the absence of evidence no such
allegation was made in the indictment.
I didn't in any sense authorize, and I certainly couldn't direct him
to do anything of this kind but my recollection of my reaction is that
I acquiesced fully in what he was proposing to do, and raised no
objection to it.
I think at sometime during that evening I reported this
conversation to Mr. Ball. I am less clear about this part of the
recollection, but I think I did report the conversation to Mr. Ball,
much in the same way as I am reporting it to you, and he saw no
objection either.
I think that is the entire State Department side of that particular
transaction.
Representative Ford. Would you check, however, Mr. Secretary,
to see if there is anything further in this regard?
Secretary Rusk. Yes; I will.
Representative Ford. Do I understand that you or somebody for
you is to summarize the USIA Voice of America broadcast that went
out for the first 3 or 4 days subsequent to the assassination and that
would be submitted for the record?
Secretary Rusk. Yes, indeed. And we can, of course, have
available to the Commission such tapes or transcripts as we have of
all those broadcasts in full, but I think we can start with the
summary and then you can have the other materials if you wish to
follow up particular points.
Representative Ford. Would they be voluminous, the originals?
Secretary Rusk. I would think they would be fairly voluminous,
but not unmanageably so.
Representative Ford. I would say for at least the first 24 hours it
might be well to have the full text of the USIA Voice of America
material that was sent out.
Secretary Rusk. Right.
Representative Ford. Do I also understand for the record that we
are to have this or others like it showing what the press reaction was
throughout the world?
Secretary Rusk. Yes, sir.
Now, the Foreign Broadcast Information Service material would
be much more voluminous because there we are receiving
broadcasts in the clear from most broadcasting countries. But we will
be in touch with your staff to show them everything that we have,
and they can have any part of it they wish or we will be glad to give
any help in terms of digesting or summarizing.
Mr. Rankin. We have been furnished some information,
considerable information, about the attitude of the foreign press as it
was recited and has come to the attention of the people from time
to time, but I don't believe we have right close, the Voice of America
we don't have right close to the date of the assassination.
The Chairman. I read a sizable file on that that came from the
State Department and very early in the life of the Commission that
seemed to encompass all of the statements that were made around
the world at that time.
Secretary Rusk. Yes.
Representative Ford. This document which you handed me, Mr.
Secretary, is for Tuesday, 26 November 1963. Are these done on a
daily basis?
Secretary Rusk. I think that one was a summary of the first 2 or
3 days, but I would——
Mr. Dulles. Summaries are done from time to time and there are
daily reports from Foreign Broadcasting Information Service covering
the Soviet Union and the satellites and another volume covering
China and southeast Asia, and so forth and so on.
Mr. Rankin. Mr. Secretary, could you give us a brief description of
that, we have been calling it this and these.
Secretary Rusk. Yes; this is a daily report or rather a supplement
to the daily report put out by the Foreign Broadcast Information
Service in what is called its world reaction series.
This apparently is a supplement to the foreign radio and press
reaction to the death of President Kennedy, and the accession of
President Johnson, prepared on 26 November 1963.
This is a daily report, the subject matter of which varies from
day to day, but I will be glad to draw together not only such digests
as we have, but also to see what we have retained in terms of the
actual broadcasts from other countries so that although it may be
voluminous it might have some material of interest to the
Commission or its staff.
Representative Ford. I think it would be particularly pertinent as
far as the Soviet Union or any of the bloc countries or Cuba,
anything in this area that could be pulled together and included in
the record, which I think would be very helpful.
Secretary Rusk. All right, sir.
Representative Ford. I have the recollection that some people
have alleged that Castro either prior to or subsequent to the
assassination, made some very inflamatory speech involving
President Kennedy.
Do you have any recollection of that?
Secretary Rusk. I don't have a recollection of a speech specially
related to time. He has made more than his share of inflamatory
speeches about this country and its leaders. But I will be glad to
furnish the Commission a schedule of his speeches, and the
character of these speeches and the texts if we have them during
this period.
Representative Ford. There was one that I vaguely recall, either
prior to or subsequent to the assassination that some people
construed to be directed specifically at President Kennedy, and I
think if there was such a speech that the Commission ought to have
it and it ought to be analyzed by the staff and by the Commission.
Secretary Rusk. We will be very glad to look into that and furnish
you with speeches made during this period or during a substantial
part of the period on both sides of the November 22 date.
I gather the Commission has Mr. Danielle's interview with Mr.
Castro on the subject. You have the published report of that.
Mr. Dulles. Was that the long interview with Castro?
Secretary Rusk. Yes; that was as close to any reflection of a thing
that he might have said personally about this that went beyond the
kind of broadcast speeches you referred to that I have seen, but——
Mr. Dulles. Do you have that available?
Secretary Rusk. We certainly can get it.
Mr. Dulles. It was in the press I guess at the time. Maybe you
have a fuller copy than we have.
Secretary Rusk. Yes; it was a rather extensive interview.
Mr. Chayes. I think the staff has it already.
Secretary Rusk. I see.
Mr. Rankin. I think Commissioner Ford is referring to that speech
of Mr. Castro which is sometimes called the slip-of-the-tongue
speech that referred in a way that may have some implications in it.
I think that might help you to identify it, Mr. Secretary.
Secretary Rusk. It might be well for me, just to complete the
sense of the atmosphere, to accompany that with the timing and the
nature of statements and speeches that were being made on our
side as a part of this continuing rather acrimonious discourse with
Cuban leadership. But I will provide full information on this.
Mr. Rankin. We would appreciate it so it would give a complete
picture.
Secretary Rusk. Yes.
Representative Ford. Do I understand now, Mr. Rankin, that what
the Secretary provides will be put in the record as exhibits?
Mr. Rankin. Mr. Chairman, I would like to offer to do that if that is
satisfactory, as a part of this record.
The Chairman. Yes, sir; it might be admitted.
Representative Ford. There is one question that I think ought to
be cleared up, you mentioned Mr. Mann who was our Ambassador at
Mexico at that time. The way the record stands now it could be
construed by somebody who wanted to so construe it that the
country in which he served us was involved in what he was
reporting. I think it ought to be made clear that is not the case.
Secretary Rusk. That is absolutely correct, sir. We never had the
slightest view that Mexico was involved in this. The problem, the
question arose because Mr. Oswald had been in Mexico, and was
known to have been in touch with some Cubans at the Cuban
Embassy in Mexico. But the Mexican authorities gave us complete
and the most helpful cooperation in full investigation of this matter.
The Chairman. Are there any further questions? Mr. Dulles.
Mr. Dulles. Had you finished?
Mr. Rankin. Yes; I have.
(Discussion off the record.)
The Chairman. Are we ready to go back on the record?
All right, the Commission will be in order.
Mr. Rankin. Mr. Chief Justice, I should like to offer in evidence at
this point Commission Exhibit No. 984 being the communication
from yourself as Chairman of the Commission to the Secretary of
State, dated March 11, 1964, and the Note Verbale in regard to the
inquiries of the Soviet Union.
And Commission Exhibit No. 985 being the responses of the
Soviet Union, including all of the medical as well as all other
responses together with the transmittal letters from the Soviet Union
and from the State Department.
The Chairman. They may be admitted under those numbers.
(Commission Exhibits Nos. 984 and 985 were marked for
identification and received in evidence.)
Mr. Rankin. I would like to assign, Mr. Chief Justice, Commission
Exhibit No. 986, if I may, to those prior communications from the
files of the Soviet Embassy in Washington that were furnished to us
by the State Department.
The Chairman. They may be admitted under that number.
(Commission Exhibit No. 986 was marked for identification and
received in evidence.)
Mr. Rankin. Commission Exhibit No. 986 will be the copies of the
records from the Soviet Embassy in Washington that were supplied
to the Commission earlier by the State Department as a part of the
records that were furnished to us by the State Department.
The Chairman. Those were the ones that were voluntarily offered
by the Russians before any request was made of them?
Mr. Rankin. Yes, Mr. Chairman.
The Chairman. They may be admitted under that number.
Mr. Rankin. Mr. Secretary, will you tell us whether you know of
any credible evidence to show or establish or tending to show any
conspiracy either domestic or foreign involved in the assassination of
President Kennedy?
Secretary Rusk. No; I have no evidence that would point in that
direction or to lead me to a conclusion that such a conspiracy
existed.
Mr. Rankin. That is all I have.
The Chairman. Are there any further questions, gentlemen?
If not, thank you very much, Mr. Secretary.
Secretary Rusk. Thank you very much, Mr. Chief Justice and
gentlemen.
TESTIMONY OF FRANCES G.
KNIGHT
The Chairman. The Commission will be in order.
Mr. Coleman, will you state to Miss Knight, please, the reason we
asked her to come here today?
Mr. Coleman. Miss Frances G. Knight is the head of the Passport
Office of the State Department.
Miss Knight. Yes, sir.
Mr. Coleman. We want to ask her concerning the standard
operating notice with respect to the lookout card system which was
in effect as of November—as of February 28, 1962, and we also
wanted to ask her concerning the decision of the Passport Office
that Mr. Oswald had not expatriated himself and, therefore, he
should be reissued his passport.
Miss Knight. Yes, sir.
The Chairman. Would you raise your right hand and be sworn,
Miss Knight?
Do you solemnly swear the testimony you are about to give
before the Commission shall be the truth, the whole truth, and
nothing but the truth, so help you God?
Miss Knight. I do.
The Chairman. Be seated. Mr. Coleman will ask you the questions.
Mr. Coleman. Miss Knight, will you state your name for the
record?
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like