0% found this document useful (0 votes)
163 views82 pages

SQL The Complete Reference 3rd Edition Steve Kaplan Download

The document provides information about various SQL-related eBooks available for download, including 'SQL The Complete Reference 3rd Edition' by Steve Kaplan. It lists multiple titles and authors, along with links to access these eBooks. Additionally, it includes details about the authors and the structure of the SQL reference book.

Uploaded by

hanorimbabe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views82 pages

SQL The Complete Reference 3rd Edition Steve Kaplan Download

The document provides information about various SQL-related eBooks available for download, including 'SQL The Complete Reference 3rd Edition' by Steve Kaplan. It lists multiple titles and authors, along with links to access these eBooks. Additionally, it includes details about the authors and the structure of the SQL reference book.

Uploaded by

hanorimbabe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Sql The Complete Reference 3rd Edition Steve

Kaplan pdf download

https://ebookgate.com/product/sql-the-complete-reference-3rd-
edition-steve-kaplan/

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


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

SQL The Complete Reference Second Edition James Groff

https://ebookgate.com/product/sql-the-complete-reference-second-
edition-james-groff/

ebookgate.com

The Complete Sailing Manual 3rd Edition Steve Sleight

https://ebookgate.com/product/the-complete-sailing-manual-3rd-edition-
steve-sleight/

ebookgate.com

Oracle SQL Plus pocket reference 3rd ed Edition Jonathan


Gennick

https://ebookgate.com/product/oracle-sql-plus-pocket-reference-3rd-ed-
edition-jonathan-gennick/

ebookgate.com

Kaplan GRE Exam Verbal Workbook 3rd Edition Kaplan

https://ebookgate.com/product/kaplan-gre-exam-verbal-workbook-3rd-
edition-kaplan/

ebookgate.com
Business Objects The Complete Reference Osborne Complete
Reference Series 1st Edition Cindi Howson

https://ebookgate.com/product/business-objects-the-complete-reference-
osborne-complete-reference-series-1st-edition-cindi-howson/

ebookgate.com

Perl The Complete Reference Brown

https://ebookgate.com/product/perl-the-complete-reference-brown/

ebookgate.com

Java The Complete Reference 7th Edition Herbert Schildt

https://ebookgate.com/product/java-the-complete-reference-7th-edition-
herbert-schildt/

ebookgate.com

Linux The Complete Reference Sixth Edition Richard


Petersen

https://ebookgate.com/product/linux-the-complete-reference-sixth-
edition-richard-petersen/

ebookgate.com

Struts The Complete Reference 1st Edition James Holmes

https://ebookgate.com/product/struts-the-complete-reference-1st-
edition-james-holmes/

ebookgate.com
SQL
The Complete Reference,
Third Edition
SQL
The Complete Reference,
Third Edition
Paul Weinberg
James Groff
Andrew Oppel

New York Chicago San Francisco


Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto
Copyright © 2010 by The McGraw-Hill Companies. All rights reserved. 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 database or retrieval system, without
the prior written permission of the publisher.

ISBN: 978-0-07-159256-7

MHID: 0-07-159256-3

The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-159255-0, MHID: 0-07-159255-5.

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 promotions, or for use in corporate training pro-
grams. To contact a representative please e-mail us at [email protected].

Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechan-
ical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any informa-
tion and is not responsible for any errors or omissions or the results obtained from the use of such information.

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, dis-
seminate, 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 non-
commercial 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 com-
ply with these terms.

THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE
ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY
INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DIS-
CLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MER-
CHANTABILITY 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 inaccuracy, error or omission, regardless of cause, in the work or for any damages result-
ing 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 liability shall
apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
About the Authors
James R. Groff is CEO of PBworks, whose hosted collaboration software helps teams of people
work together more effectively and efficiently. Earlier, Groff was CEO of TimesTen, the leading
provider of in-memory SQL databases. He led TimesTen from its early days through eight years of
growth and a successful acquisition by Oracle in 2005, where he served as a senior vice president,
and Oracle TimesTen became Oracle’s flagship real-time database product. Groff was the
cofounder, with Paul Weinberg, of Network Innovations Corporation, a developer of SQL-based
networking software, and coauthor with him of Understanding UNIX: A Conceptual Guide as well
as this book. Groff has also held senior division management and marketing positions at Apple
Computer and Hewlett-Packard. He holds a BS in Mathematics from the Massachusetts Institute
of Technology and an MBA from Harvard University.
Paul N. Weinberg is a senior vice president at SAP, where he runs core MDM (Master Data
Management) development. Prior to working at SAP, Weinberg was president of A2i, Inc., which
was acquired by SAP in 2004 for its enterprisewide platform for product content management and
catalog publishing. Weinberg was the cofounder, with James Groff, of Network Innovations
Corporation, a pioneer in client/server database access that was acquired by Apple Computer in
1988, and coauthor with him of Understanding UNIX:
A Conceptual Guide as well as this book. 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 6
million copies sold. He holds a BS from the University of Michigan and an MS from Stanford
University, both in Computer Science.
Andrew J. (Andy) Oppel is lead data modeler at Blue Shield of California. In addition, he has
served as a part-time instructor in database technology with the University of California at
Berkeley, Extension for more than 20 years. Andy has designed and implemented hundreds of
databases for a wide range of applications, including heath care, banking, insurance, apparel
manufacturing, telecommunications, wireless communications, and human resources. He is the
author of Databases Demystified, SQL Demystified, and Databases: A Beginner’s Guide and is coauthor
of SQL: A Beginner’s Guide. He holds a BA in Computer Science from Transylvania University
(Lexington, KY).

About the Technical Editor


Aaron Davenport has been working with SQL-based RDBMS technologies for over ten years. He
is currently a principal at LCS Technologies, Inc., a Sacramento and San Francisco Bay Area
database consulting firm specializing in performance tuning, application development, and
database architecture. Prior to joining LCS, Aaron had tenures at Yahoo!, Gap Inc., and Blue Shield
of California.
Contents at a Glance

Part I An Overview of SQL


1 Introduction ..................................................... 3
2 A Quick Tour of SQL ............................................. 13
3 SQL in Perspective ............................................... 21
4 Relational Databases ............................................. 45

Part II Retrieving Data


5 SQL Basics ...................................................... 63
6 Simple Queries .................................................. 85
7 Multitable Queries (Joins) ......................................... 119
8 Summary Queries ................................................ 163
9 Subqueries and Query Expressions ................................. 187

Part III Updating Data


10 Database Updates ................................................ 231
11 Data Integrity .................................................... 247
12 Transaction Processing ............................................ 281

Part IV Database Structure


13 Creating a Database .............................................. 315
14 Views ........................................................... 355
15 SQL Security ..................................................... 375
16 The System Catalog .............................................. 399

vii
viii SQL: The Complete Reference

Part V Programming with SQL


17 Embedded SQL .................................................. 429
18 Dynamic SQL* ................................................... 477
19 SQL APIs ........................................................ 521

Part VI SQL Today and Tomorrow


20 Database Processing and Stored Procedural SQL ..................... 617
21 SQL and Data Warehousing ....................................... 667
22 SQL and Application Servers ...................................... 681
23 SQL Networking and Distributed Databases ........................ 699
24 SQL and Objects ................................................. 735
25 SQL and XML .................................................... 769
26 Specialty Databases .............................................. 805
27 The Future of SQL ................................................ 819

Part VII Appendixes


A The Sample Database ............................................. 835
B DBMS Vendor Profiles ............................................ 841
C SQL Syntax Reference ............................................ 857

Index ........................................................... 865


Contents ix

Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

Part I An Overview of SQL


1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The SQL Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
The Role of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
SQL Success Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Vendor Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Portability Across Computer Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Official SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Early IBM Commitment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Microsoft Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Relational Foundation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
High-Level, English-Like Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Interactive, Ad Hoc Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Programmatic Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Multiple Views of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Complete Database Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Dynamic Data Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Client/Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Enterprise Application Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Extensibility and Object Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Internet Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Java Integration (JDBC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Open Source Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Industry Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 A Quick Tour of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
A Simple Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Summarizing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Adding Data to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Deleting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Updating the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Protecting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

ix
x SQL: The Complete Reference

3 SQL in Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
SQL and the Evolution of Database Management . . . . . . . . . . . . . . . . . . . . . . 21
A Brief History of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
The Early Years . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Early Relational Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
IBM Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Commercial Acceptance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The ANSI/ISO Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Other Early SQL Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
ODBC and the SQL Access Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
JDBC and Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
SQL and Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
SQL and Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Centralized Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
File Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Client/Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Multitier Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Proliferation of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SQL on Mainframes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SQL on Minicomputers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SQL on UNIX-Based Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
SQL on Personal Computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
SQL and Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
SQL and Workgroup Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
SQL, Data Warehousing, and Business Intelligence . . . . . . . . . . . . . . 40
SQL and Internet Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4 Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Early Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
File Management Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Hierarchical Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Network Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
The Relational Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The Sample Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Primary Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Codd’s 12 Rules for Relational Databases* . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Contents xi

Part II Retrieving Data


5 SQL Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Table Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Column Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Numeric Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Date and Time Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Symbolic Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Built-In Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Missing Data (NULL Values) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6 Simple Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The SELECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The SELECT Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The FROM Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Query Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Simple Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Calculated Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Selecting All Columns (SELECT *) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Duplicate Rows (DISTINCT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Row Selection (WHERE Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The Comparison Test (=, <>, <, <=, >, >=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The Range Test (BETWEEN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The Set Membership Test (IN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
The Pattern Matching Test (LIKE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Null Value Test (IS NULL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Compound Search Conditions (AND, OR, and NOT) . . . . . . . . . . . . 107
Sorting Query Results (ORDER BY Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Rules for Single-Table Query Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Combining Query Results (UNION)* . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Unions and Duplicate Rows* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Unions and Sorting* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Multiple UNIONs* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
xii SQL: The Complete Reference

7 Multitable Queries (Joins) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119


A Two-Table Query Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Simple Joins (Equi-Joins) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Parent/Child Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
An Alternative Way to Specify Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Joins with Row Selection Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Multiple Matching Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Natural Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Queries with Three or More Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Other Equi-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Non-Equi-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
SQL Considerations for Multitable Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Qualified Column Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
All-Column Selections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Self-Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Table Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Multitable Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
The Structure of a Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Table Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Rules for Multitable Query Processing . . . . . . . . . . . . . . . . . . . . . . . . . 143
Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Left and Right Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Older Outer Join Notation* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Joins and the SQL Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Inner Joins in Standard SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Outer Joins in Standard SQL* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Cross Joins in Standard SQL* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Multitable Joins in Standard SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
8 Summary Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Column Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Computing a Column Total (SUM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Computing a Column Average (AVG) . . . . . . . . . . . . . . . . . . . . . . . . . 166
Finding Extreme Values (MIN and MAX) . . . . . . . . . . . . . . . . . . . . . . 166
Counting Data Values (COUNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Column Functions in the Select List . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
NULL Values and Column Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Duplicate Row Elimination (DISTINCT) . . . . . . . . . . . . . . . . . . . . . . . 173
Grouped Queries (GROUP BY Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Multiple Grouping Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Restrictions on Grouped Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
NULL Values in Grouping Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Contents xiii

Group Search Conditions (HAVING Clause) . . . . . . . . . . . . . . . . . . . . . . . . . . 182


Restrictions on Group Search Conditions . . . . . . . . . . . . . . . . . . . . . . . 185
NULL Values and Group Search Conditions . . . . . . . . . . . . . . . . . . . . 186
HAVING Without GROUP BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
9 Subqueries and Query Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Using Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
What Is a Subquery? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Subqueries in the WHERE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Outer References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Subquery Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The Subquery Comparison Test (=, <>, <, <=, >, >=) . . . . . . . . . . . . . 192
The Set Membership Test (IN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
The Existence Test (EXISTS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Quantified Tests (ANY and ALL)* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Subqueries and Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Nested Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Correlated Subqueries* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Subqueries in the HAVING Clause* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Subquery Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Advanced Queries* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Scalar-Valued Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Row-Valued Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Table-Valued Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Query Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
SQL Queries: A Final Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

Part III Updating Data


10 Database Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Adding Data to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Single-Row INSERT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
The Multirow INSERT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Bulk Load Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Deleting Data from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
The DELETE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Deleting All Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
DELETE with Subquery* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Modifying Data in the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
The UPDATE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Updating All Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
UPDATE with Subquery* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
xiv SQL: The Complete Reference

11 Data Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247


What Is Data Integrity? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Required Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Simple Validity Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Column Check Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Entity Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Other Uniqueness Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Uniqueness and NULL Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Referential Integrity Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Delete and Update Rules* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Cascaded Deletes and Updates* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Referential Cycles* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Foreign Keys and NULL Values* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Advanced Constraint Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
SQL Constraint Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Deferred Constraint Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Business Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
What Is a Trigger? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Triggers and Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Trigger Advantages and Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . 277
Triggers and the SQL Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
12 Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
What Is a Transaction? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
The ANSI/ISO SQL Transaction Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
The START TRANSACTION and SET TRANSACTION Statements . . . 284
The SAVEPOINT and RELEASE SAVEPOINT Statements . . . . . . . . 286
The COMMIT and ROLLBACK Statements . . . . . . . . . . . . . . . . . . . . . 286
Transactions: Behind the Scenes* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Transactions and Multiuser Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
The Lost Update Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
The Uncommitted Data Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
The Inconsistent Data Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
The Phantom Insert Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Concurrent Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Locking* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Locking Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Shared and Exclusive Locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Deadlocks* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Advanced Locking Techniques* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Contents xv

Versioning* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Versioning in Operation* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Versioning Advantages and Disadvantages* . . . . . . . . . . . . . . . . . . . . 311
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

Part IV Database Structure


13 Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
The Data Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Table Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Creating a Table (CREATE TABLE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Removing a Table (DROP TABLE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Changing a Table Definition (ALTER TABLE) . . . . . . . . . . . . . . . . . . . 328
Constraint Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Aliases and Synonyms (CREATE/DROP ALIAS) . . . . . . . . . . . . . . . . . . . . . . 333
Indexes (CREATE/DROP INDEX) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Managing Other Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Single-Database Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Multidatabase Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Multilocation Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Databases on Multiple Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Database Structure and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . 348
Catalogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
14 View ............................................................ 355
What Is a View? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
How the DBMS Handles Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Advantages of Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Disadvantages of Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Creating a View (CREATE VIEW) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Horizontal Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Vertical Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Row/Column Subset Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Grouped Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Joined Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Updating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
View Updates and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . 367
View Updates in Commercial SQL Products . . . . . . . . . . . . . . . . . . . . 368
Checking View Updates (CHECK OPTION) . . . . . . . . . . . . . . . . . . . . 368
xvi SQL: The Complete Reference

Dropping a View (DROP VIEW) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371


Materialized Views* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
15 SQL Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
SQL Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
User-Ids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Security Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Views and SQL Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Granting Privileges (GRANT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Column Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Passing Privileges (GRANT OPTION) . . . . . . . . . . . . . . . . . . . . . . . . . 389
Revoking Privileges (REVOKE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
REVOKE and the GRANT OPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
REVOKE and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . . . . 394
Role-Based Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
16 The System Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
What Is the System Catalog? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
The Catalog and Query Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
The Catalog and the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . 401
Catalog Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Table Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Column Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
View Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Relationship Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
User Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Privileges Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
The SQL Information Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Other Catalog Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426

Part V Programming with SQL


17 Embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Programmatic SQL Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
DBMS Statement Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Embedded SQL Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Developing an Embedded SQL Program . . . . . . . . . . . . . . . . . . . . . . . 434
Running an Embedded SQL Program . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Contents xvii

Simple Embedded SQL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439


Declaring Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Using Host Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Data Retrieval in Embedded SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Single-Row Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Multirow Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Cursor-Based Deletes and Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Cursors and Transaction Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
18 Dynamic SQL* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Limitations of Static SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Dynamic SQL Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Dynamic Statement Execution (EXECUTE IMMEDIATE) . . . . . . . . . . . . . . . 480
Two-Step Dynamic Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
The PREPARE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
The EXECUTE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Dynamic Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
The DESCRIBE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
The DECLARE CURSOR Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
The Dynamic OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
The Dynamic FETCH Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
The Dynamic CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Dynamic SQL Dialects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Dynamic SQL in Oracle* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Dynamic SQL and the SQL Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Basic Dynamic SQL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
The Standard SQLDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
The SQL Standard and Dynamic SQL Queries . . . . . . . . . . . . . . . . . . 515
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
19 SQL APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
API Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
The dblib API (SQL Server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Basic SQL Server Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
SQL Server Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Positioned Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Dynamic Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
ODBC and the SQL/CLI Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
The Call-Level Interface Standardization . . . . . . . . . . . . . . . . . . . . . . . 549
CLI Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
CLI Statement Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
CLI Errors and Diagnostic Information . . . . . . . . . . . . . . . . . . . . . . . . 575
CLI Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
CLI Information Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
xviii SQL: The Complete Reference

The ODBC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579


The Structure of ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
ODBC and DBMS Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
ODBC Catalog Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Extended ODBC Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
The Oracle Call Interface (OCI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
OCI Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
Oracle Server Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
Statement Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
Query Results Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Descriptor Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Transaction Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Java Database Connectivity (JDBC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
JDBC History and Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
JDBC Implementations and Driver Types . . . . . . . . . . . . . . . . . . . . . . 593
The JDBC API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614

Part VI SQL Today and Tomorrow


20 Database Processing and Stored Procedural SQL . . . . . . . . . . . . . . . . . . . . . 617
Procedural SQL Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
A Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
Using Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Creating a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Calling a Stored Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Stored Procedure Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
Statement Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
Returning Values via Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Conditional Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Repeated Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
Other Flow-of-Control Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
Cursor-Based Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
Handling Error Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
Advantages of Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Stored Procedure Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
System-Defined Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
External Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
Advantages and Disadvantages of Triggers . . . . . . . . . . . . . . . . . . . . . 649
Triggers in Transact-SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
Triggers in Informix SPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Triggers in Oracle PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
Other Trigger Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
Contents xix

Stored Procedures, Functions, Triggers, and the SQL Standard . . . . . . . . . . 655


The SQL/PSM Stored Procedures Standard . . . . . . . . . . . . . . . . . . . . 656
The SQL/PSM Triggers Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
21 SQL and Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
Data Warehousing Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
Components of a Data Warehouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
The Evolution of Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . 670
Database Architecture for Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
Fact Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
Star Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Multilevel Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
SQL Extensions for Data Warehousing . . . . . . . . . . . . . . . . . . . . . . . . . 676
Warehouse Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Load Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
22 SQL and Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
SQL and Web Sites: Early Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Application Servers and Three-Tier Web Site Architectures . . . . . . . . . . . . . 682
Database Access from Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
EJB Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
Session Bean Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
Entity Bean Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
EJB 2.0 Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692
EJB 3.0 Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Open Source Application Development . . . . . . . . . . . . . . . . . . . . . . . . 695
Application Server Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
23 SQL Networking and Distributed Databases . . . . . . . . . . . . . . . . . . . . . . . . 699
The Challenge of Distributed Data Management . . . . . . . . . . . . . . . . . . . . . . 700
Distributing Data: Practical Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Remote Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
Remote Data Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
Table Extracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
Table Replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
Updateable Replicas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713
Replication Trade-Offs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Typical Replication Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Distributed Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Remote Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
Remote Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
Distributed Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
Distributed Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
xx SQL: The Complete Reference

The Two-Phase Commit Protocol* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724


Network Applications and Database Architecture . . . . . . . . . . . . . . . . . . . . . 727
Client/Server Applications and Database Architecture . . . . . . . . . . . 728
Client/Server Applications with Stored Procedures . . . . . . . . . . . . . 729
Enterprise Applications and Data Caching . . . . . . . . . . . . . . . . . . . . . 730
High-Volume Internet Data Management . . . . . . . . . . . . . . . . . . . . . . 731
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
24 SQL and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
Object-Oriented Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
Object-Oriented Database Characteristics . . . . . . . . . . . . . . . . . . . . . . 736
Pros and Cons of Object-Oriented Databases . . . . . . . . . . . . . . . . . . . 737
Objects and the Database Market . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738
Object-Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
Large Object Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
LOBs in the Relational Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
Specialized LOB Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Abstract (Structured) Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Defining Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746
Manipulating Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 749
Table Inheritance: Implementing Object Classes . . . . . . . . . . . . . . . . . 751
Sets, Arrays, and Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
Defining Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755
Querying Collection Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
Manipulating Collection Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
Collections and Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 760
User-Defined Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762
Methods and Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
Object Support in the SQL Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
25 SQL and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
What Is XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
XML Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
XML for Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773
XML and SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
Elements vs. Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775
Using XML with Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
XML Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778
XML Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782
XML Data Exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
XML Storage and Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
Contents xxi

XML and Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788


Document Type Definitions (DTDs) . . . . . . . . . . . . . . . . . . . . . . . . . . . 790
XML Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
XML and Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797
XQuery Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
Query Processing in XQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
XML Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
26 Specialty Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
Very Low Latency and In-Memory Databases . . . . . . . . . . . . . . . . . . . . . . . . . 805
Anatomy of an In-Memory Database . . . . . . . . . . . . . . . . . . . . . . . . . . 806
In-Memory Database Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
Caching with In-Memory Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
Complex Event-Processing and Stream Databases . . . . . . . . . . . . . . . . . . . . . 810
Continuous Queries in Stream Databases . . . . . . . . . . . . . . . . . . . . . . 811
Stream Database Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
Stream Database Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
Embedded Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814
Embedded Database Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . 815
Embedded Database Implementations . . . . . . . . . . . . . . . . . . . . . . . . . 815
Mobile Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
Mobile Database Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
Mobile Database Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
27 The Future of SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Database Market Trends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820
Enterprise Database Market Maturity . . . . . . . . . . . . . . . . . . . . . . . . . . 820
Market Diversity and Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 821
Packaged Enterprise Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822
Software-as-a-Service (SaaS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
Hardware Performance Gains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
Database Server Appliances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824
SQL Standardization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825
SQL in the Next Decade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826
Distributed Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826
Massive Data Warehousing for Business Optimization . . . . . . . . . . . 826
Ultrahigh-Performance Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 827
Internet and Network Services Integration . . . . . . . . . . . . . . . . . . . . . 828
Embedded Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
Object Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
Cloud-Based and Horizontally Scalable Databases . . . . . . . . . . . . . . 830
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832
xxii SQL: The Complete Reference

Part VII Appendixes


A The Sample Database ............................................. 835
B DBMS Vendor Profiles ............................................ 841
C SQL Syntax Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
Data Definition Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
Access Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
Basic Data Manipulation Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
Transaction-Processing Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 860
Cursor-Based Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 860
Query Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 860
Search Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 862
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863
Statement Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863
Simple Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864
Index ........................................................... 865
Introduction xxiii

Acknowledgments

S
pecial thanks to Andy Oppel, our new coauthor for this third edition of SQL: The
Complete Reference. His impressive high-level mastery of the subject matter coupled
with his meticulous attention to detail made this a better book, and we are fortunate
to have had his involvement.
—Jim and Paul

It’s an honor to join such an accomplished team of authors for this edition of SQL: The
Complete Reference. My thanks for the excellent support of the entire McGraw-Hill team for
their tireless support in this effort. In particular I wish to thank technical editor Aaron
Davenport and copy editor Jan Jue for their persistence and attention to detail, which
contributed so much to the overall quality of this book.
—Andy

xxiii
Introduction

S
QL: The Complete Reference, Third Edition provides a comprehensive, in-depth
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. Most of the examples in this book are
based on the sample database described in Appendix A. The sample database contains
data that supports a simple order-processing application for a small distribution company.
Appendix A also contains instructions for downloading the SQL statements required to
create and populate the sample database tables in a DBMS of you choice, such as Oracle,
SQL Server, MySQL, and DB2. This allows you to try the examples in the book yourself
and gain actual experience writing and running SQL statements.
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.

xxv
xxvi SQL: The Complete Reference

How This Book Is Organized


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

• Part I, “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 I 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 II, “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 III, “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 IV, “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 V, “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 standard call-level interface for Java, as well as
proprietary call-level interfaces such as Oracle’s OCI API.
• Part VI, “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, specialty databases, 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.
Introduction xxvii

Conventions Used in This Book


SQL: The Complete Reference, Third 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, Third 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 to
describe the differences among the most popular SQL products, including Oracle, Microsoft
SQL Server, IBM’s DB2 Universal Database and Informix, Sybase, and MySQL. It also
explains the importance of SQL-based standards, such as ODBC and JDBC, and the ANSI/
ISO standards for SQL and SQL-related technologies. This third edition contains new
chapters and sections that cover the latest SQL innovations, in the areas of object-relational
technologies, XML, and application server architectures.
If you are new to SQL, this book offers comprehensive, step-by-step treatment of the
language, building from simple queries to more advanced concepts. The structure of the
book will allow you to quickly start using SQL, but the book will continue to be valuable as
you begin to use the more complex features of the language. You can create the sample
database using an SQL script available on the McGraw-Hill website (see Appendix A) and
use it to try out the examples and build your SQL skills.
If you are a data processing professional, architect, or manager, this book will give
you a perspective on the impact that SQL is having across the information technology
industry—from personal computers to mainframes to data warehousing to Internet web
sites and Internet-based distributed applications. The early chapters describe the history
of SQL, its role in the market, and its evolution from earlier database technologies. Later
chapters describe the future of SQL and the development of new database technologies,
such as distributed databases, object-oriented extensions to SQL, business intelligence
databases, and database/XML integration.
xxviii SQL: The Complete Reference

If you are a programmer, this book offers a very complete treatment of programming with
SQL. Unlike the reference manuals of many DBMS products, it offers a conceptual framework
for SQL programming, explaining the why as well as the how of developing a SQL-based
application. It contrasts the SQL programming interfaces offered by all of the leading SQL
products, including embedded SQL, dynamic SQL, ODBC, JDBC, and proprietary APIs
such as the Oracle Call Interface. The description and comparison of programming techniques
provides a perspective not found in any other book.
If you are selecting a DBMS product, this book offers a comparison of the SQL features,
advantages, and benefits offered by the various DBMS vendors. The differences between
the leading DBMS products are explained, not only in technical terms, but also in terms
of their impact on applications and their evolving competitive position in the marketplace.
The “sample database” can be used to try these features in a prototype of your own
application.
In short, both technical and nontechnical users can benefit from this book. It is the most
comprehensive source of information available about the SQL language, SQL features and
benefits, popular SQL-based products, the history of SQL, and the impact of SQL on the
future direction of the information technology industry.
PART
I
An Overview of SQL CHAPTER 1
Introduction
CHAPTER 2
A Quick Tour of SQL

T
he first four chapters of this book provide a perspective and CHAPTER 3
a quick introduction to SQL. Chapter 1 describes what SQL is SQL in Perspective
and explains its major features and benefits. In Chapter 2, CHAPTER 4
a quick tour of SQL shows you many of its capabilities with simple, Relational Databases
rapid-fire examples. Chapter 3 offers a market perspective of SQL
by tracing its history, describing the SQL standards and the major
vendors of SQL-based products, and by identifying the reasons for
SQL’s prominence today. Chapter 4 describes the relational data
model upon which SQL is based and compares it with earlier data
models.
This page intentionally left blank
CHAPTER
1
Introduction

T
he SQL language and relational database systems based on it constitute one of the
most important foundation technologies in the computer industry. Over the last three
decades, SQL has grown from its first commercial use into a computer product and
services market segment worth tens of billions of dollars per year, and SQL stands today as
the standard computer database language. Hundreds of database products now support
SQL, running on computer systems from mainframes to personal computers. A SQL-based
database may even be embedded in your mobile phone or PDA, or in the entertainment
system of your car. An official international SQL standard has been adopted and expanded
several times. Every major enterprise software product relies on SQL for its data management,
and SQL is at the core of the flagship database products from Microsoft, Oracle, and IBM,
three of the largest software companies in the world. SQL is also at the heart of open-source
database products such as MySQL and Postgres that are helping to fuel the popularity of
Linux and the open source movement. From its obscure beginnings as an IBM research project,
SQL has grown to become both an important piece of information technology and a powerful
market force.
What, exactly, is SQL? Why is it important? What can it do, and how does it work? If
SQL is really a standard, why do we have so many different versions and dialects? How do
popular SQL products like SQL Server, Oracle, MySQL, Sybase, and DB2 compare? How
does SQL relate to Microsoft standards such as ODBC and .NET? How does JDBC link SQL
to the world of Java and object technology? What role does it play in the Service-Oriented
Architecture (SOA) and web services being embraced by enterprise IT organizations? Does
SQL really scale from mainframes to handheld devices? Has it really delivered the
performance needed for high-volume transaction processing? How will SQL impact the
way you use computers, and how can you get the most out of this important data
management tool? This book answers those questions by giving you a complete perspective
and a solid working knowledge of SQL.

3
4 Part I: An Overview of SQL

The SQL Language


SQL is a tool for organizing, managing, and retrieving data stored by a computer database.
The original name given it by IBM was Structured English Query Language, shortened to the
acronym SEQUEL. When IBM discovered that SEQUEL was a trademark owned by the Hawker
Siddeley Aircraft Company of the United Kingdom, they shortened the acronym to SQL. The
word “English” was then dropped from the spelled-out name to match the new acronym. To
this day, you will hear the acronym SQL pronounced as either a word (“sequel”) or as a string
of letters (“S-Q-L”), and while the latter is generally preferred, both are considered correct. As
the name implies, SQL is a computer language that you use to interact with a database. In fact,
SQL works with one specific type of database, called a relational database, which has become
the mainstream way to organize data across a very broad range of computer applications.
Figure 1-1 shows how SQL works. The computer system in the figure has a database that
stores important information. If the computer system is in a business, the database might
store inventory, production, sales, or payroll data. On a personal computer, the database
might store data about the checks you have written, lists of people and their phone numbers,
or data extracted from a larger computer system. The computer program that controls the
database is called a database management system (DBMS).
When you need to retrieve data from a database, you use the SQL to make the request.
The DBMS processes the SQL request, retrieves the requested data, and returns it to you.
This process of requesting data from a database and receiving the results is called a database
query—hence the name Structured Query Language.
“Structured Query Language” is actually somewhat of a misnomer. First of all, SQL is
far more than a query tool, although that was its original purpose, and retrieving data is still
one of its most important functions. SQL is used to control all of the functions that a DBMS
provides for its users, including

FIGURE 1-1 Using SQL for database access


Chapter 1: Introduction 5

• Data definition SQL lets a user define the structure and organization of the stored
data and relationships among the stored data items.
• Data retrieval SQL allows a user or an application program to retrieve stored data

PART I
from the database and use it.
• Data manipulation SQL allows a user or an application program to update the
database by adding new data, removing old data, and modifying previously
stored data.
• Access control SQL can be used to restrict a user’s ability to retrieve, add, and
modify data, protecting stored data against unauthorized access.
• Data sharing SQL is used to coordinate data sharing by concurrent users, ensuring
that changes made by one user do not inadvertently wipe out changes made at
nearly the same time by another user.
• Data integrity SQL defines integrity constraints in the database, protecting it from
corruption due to inconsistent updates or system failures.

SQL is thus a comprehensive language for controlling and interacting with a database
management system.
Second, SQL is not really a complete computer language like COBOL, C, C++, or Java.
Instead, SQL is a database sublanguage, consisting of about 40 statements specialized for
database management tasks. These SQL statements can be embedded into another language
such as COBOL or C to extend that language for use in database access. Alternatively,
the statements can be explicitly sent to a database management system for processing,
via a call-level interface from a language such as C, C++, or Java, or via messages sent over
a computer network.
SQL also differs from other computer languages because it describes what the user
wants the computer to do rather than how the computer should do it. (In more technical
terms, SQL is a declarative or descriptive language rather than a procedural one.) SQL
contains no IF statement for testing conditions, and no GOTO, DO, or FOR statements for
program flow control. Rather, SQL statements describe how a collection of data is to be
organized, or what data is to be retrieved or added to the database. The sequence of steps
to do those tasks is left for the DBMS to determine.
Finally, SQL is not a particularly structured language, especially when compared with
highly structured languages such as C, Pascal, or Java. Instead, SQL statements resemble
English sentences, complete with “noise words” that don’t add to the meaning of the
statement but make it read more naturally. The SQL has quite a few inconsistencies and also
some special rules to prevent you from constructing SQL statements that look perfectly legal
but that don’t make sense.
Despite the inaccuracy of its name, SQL has emerged as the standard language for using
relational databases. SQL is both a powerful language and one that is relatively easy to
learn. The quick tour of SQL in Chapter 2 will give you a good overview of the language
and its capabilities.
6 Part I: An Overview of SQL

The Role of SQL


SQL is not itself a database management system, nor is it a stand-alone product. You cannot
go to a computer retailer or a web site selling computer software and buy SQL. Instead,
SQL is an integral part of a database management system, a language and a tool for
communicating with the DBMS. Figure 1-2 shows some of the components of a typical
DBMS and how SQL links them together.
The database engine is the heart of the DBMS, responsible for actually structuring, storing,
and retrieving the data in the database. It accepts SQL requests from other DBMS components
(such as a forms facility, report writer, or interactive query facility), from user-written
application programs, and even from other computer systems. As the figure shows, SQL plays
many different roles:

• SQL is an interactive query language. Users type SQL commands into an interactive
SQL program to retrieve data and display it on the screen, providing a convenient,
easy-to-use tool for ad hoc database queries.
• SQL is a database programming language. Programmers embed SQL commands into
their application programs to access the data in a database. Both user-written
programs and database utility programs (such as report writers and data entry
tools) use this technique for database access.

FIGURE 1-2 Components of a typical database management system


Chapter 1: Introduction 7

• SQL is a database administration language. The database administrator responsible for


managing a minicomputer or mainframe database uses SQL to define the database
structure and to control access to the stored data.

PART I
• SQL is a client/server language. Personal computer programs use SQL to communicate
over a network with database servers that store shared data. This client/server
architecture is used by many popular enterprise-class applications.
• SQL is an Internet data access language. Internet web servers that interact with
corporate data and Internet application servers all use SQL as a standard language
for accessing corporate databases, often by embedding SQL database access within
popular scripting languages like PHP or Perl.
• SQL is a distributed database language. Distributed database management systems use
SQL to help distribute data across many connected computer systems. The DBMS
software on each system uses SQL to communicate with the other systems, sending
requests for data access.
• SQL is a database gateway language. In a computer network with a mix of different
DBMS products, SQL is often used in a gateway that allows one brand of DBMS to
communicate with another brand.

SQL has thus emerged as a useful, powerful tool for linking people, computer programs,
and computer systems to the data stored in a relational database.

SQL Success Factors


In historical terms, SQL has been an extraordinarily successful information technology.
Think about the computer market in the mid-1980s, when SQL first started to become
important. Mainframes and minicomputers dominated corporate computing. The IBM
personal computer had been introduced only a few years before, and the MS-DOS command
line was its user interface. IBM’s mainframe operating systems and minicomputer operating
systems from Digital Equipment, Data General, Hewlett-Packard, and others dominated
business computing. Proprietary networking schemes like IBM’s SNA or Digital Equipment’s
DECnet linked computers together. The Internet was still a tool for collaboration among
research labs, and the World Wide Web had not yet appeared on the scene. COBOL, C, and
Pascal were dominant computer languages; object-oriented programming was only
beginning to emerge; and Java had not been invented.
Across all of these areas of computer technology—from computer hardware to operating
systems to networking to languages—the important key technologies of the mid-1980s
have faded or become obsolete, replaced by significant new ones. But in the world of data
management, the relational database and SQL continue to dominate the landscape. They
have expanded over the years to support new hardware, operating systems, networks, and
languages, but despite many attempts to dethrone them, the core relational model and the
SQL have thrived and remain the dominant forces in data management. Here are some of the
major features and market forces that have contributed to this success over the past 25 years:

• Vendor independence
• Portability across computer systems
8 Part I: An Overview of SQL

• Official SQL standards


• Early IBM commitment
• Microsoft support
• Relational foundation
• High-level, English-like structure
• Interactive, ad hoc queries
• Programmatic database access
• Multiple views of data
• Complete database language
• Dynamic data definition
• Client/Server architecture
• Enterprise application support
• Extensibility and object technology
• Internet database access
• Java integration (JDBC)
• Open source support
• Industry infrastructure

The sections that follow briefly describe each of these and how they contributed to
SQL’s success.

Vendor Independence
SQL is offered by all of the leading DBMS vendors, and no new database product over the
last decade has been highly successful without SQL support. A SQL-based database and the
programs that use it can be moved from one DBMS to another vendor’s DBMS with
minimal conversion effort and little retraining of personnel. Database tools such as query
tools, report writers, and application generators work with many different brands of SQL
databases. The vendor independence thus provided by SQL was one of the most important
reasons for its early popularity and remains an important feature today.

Portability Across Computer Systems


SQL-based database products run on computer systems ranging from mainframes and
midrange systems to personal computers, workstations, a wide range of specialized server
computers, and even handheld devices. They operate on stand-alone computer systems, in
departmental local area networks, and in enterprisewide or Internetwide networks. SQL-
based applications that begin on single-user or departmental server systems can be moved
to larger server systems as they grow. Data from corporate SQL-based databases can be
extracted and downloaded into departmental or personal databases. Finally, economical
personal computers can be used to test a prototype of a SQL-based database application
before moving it to an expensive multiuser system.
Chapter 1: Introduction 9

Official SQL Standards


An official standard for SQL was initially published by the American National Standards
Institute (ANSI) and the International Standards Organization (ISO) in 1986, and was

PART I
expanded in 1989 and again in 1992, 1999, 2003, and 2006. SQL is also a U.S. Federal
Information Processing Standard (FIPS), making it a key requirement for large government
computer contracts. Over the years, other international, government, and vendor groups
have pioneered the standardization of new SQL capabilities, such as call-level interfaces or
object-based extensions. Many of these new initiatives have been incorporated into the
ANSI/ISO standard over time. The evolving standards serve as an official stamp of
approval for SQL and have speeded its market acceptance.

Early IBM Commitment


SQL was originally invented by IBM researchers and fairly quickly became a strategic
product for IBM based on its flagship DB2 database. SQL support is available on all major
IBM product families, from personal computers through midrange systems and UNIX-based
servers to IBM mainframes. IBM’s initial work provided a clear signal of IBM’s direction for
other database and system vendors to follow early in the development of SQL and relational
databases. Later, IBM’s commitment and broad support speeded the market acceptance of
SQL. In the 1970s, IBM was the dominant force in business computing, so its early and
sustained support as the inventor and champion of SQL ensured its early importance.

Microsoft Support
Microsoft has long considered database access a key part of its Windows personal computer
software architecture. Both desktop and server versions of Windows provide standardized
relational database access through Open Database Connectivity (ODBC), a SQL-based
call-level API (application programming interface). Leading Windows software applications
(spreadsheets, word processors, databases, etc.) from Microsoft and other vendors
support ODBC, and all leading SQL databases provide ODBC access. Microsoft has
enhanced ODBC support with higher-level, more object-oriented database access layers
over the years, including data management support in .NET today. But these new
technologies could always interact with relational databases through the ODBC/SQL
layers below. When Microsoft began its effort in the late 1980s to make Windows a viable
server operating system, it introduced SQL Server as its own SQL-based offering. SQL
Server continues today as a flagship Microsoft product and as a key component of the
Microsoft .NET architecture for web services.

Relational Foundation
SQL is a language for relational databases, and it has become popular along with the
relational database model. The tabular, row/column structure of a relational database
is intuitive to users, keeping the SQL simple and easy to understand. The relational
model also has a strong theoretical foundation that has guided the evolution and
implementation of relational databases. Riding a wave of acceptance brought about by
the success of the relational model, SQL has become the database language for relational
databases.
10 Part I: An Overview of SQL

High-Level, English-Like Structure


SQL statements look like simple English sentences, making SQL relatively easy to learn and
understand. This is in part because SQL statements describe the data to be retrieved, rather
than specifying how to find the data. Tables and columns in a SQL database can have long,
descriptive names. As a result, most SQL statements “say what they mean” and can be read
as clear, natural sentences.

Interactive, Ad Hoc Queries


SQL is an interactive query language that gives users ad hoc access to stored data. Using
SQL interactively, a user can get answers even to complex questions in minutes or seconds,
in sharp contrast to the days or weeks it would take for a programmer to write a custom
report program. Because of the SQL ad hoc query power, data is more accessible and can be
used to help an organization make better, more informed decisions. SQL’s ad hoc query
capability was an important advantage over nonrelational databases early in its evolution
and more recently has continued as a key advantage over pure object-based databases.

Programmatic Database Access


SQL is also a database language used by programmers to write applications that access a
database. The same SQL statements are used for both interactive and programmatic access,
so the database access parts of a program can be tested first with interactive SQL and then
embedded into the program. In contrast, nonrelational or object-oriented databases
provided one set of tools for programmatic access and a separate query facility for ad hoc
requests, without any synergy between the two modes of access.

Multiple Views of Data


Using SQL, the creator of a database can give different users of the database different views
of its structure and contents. For example, the database can be constructed so that each user
sees data only for his or her department or sales region. In addition, data from several
different parts of the database can be combined and presented to the user as a simple row/
column table. SQL views can thus be used to enhance the security of a database and to tailor
it to the particular needs of individual users while preserving the fundamental row/column
structure of the data.

Complete Database Language


SQL was first developed as an ad hoc query language, but its powers now go far beyond
data retrieval. SQL provides a complete, consistent language for creating a database,
managing its security, updating its contents, retrieving data, and sharing data among many
concurrent users. SQL concepts that are learned in one part of the language can be applied
to other SQL commands, making users more productive.

Dynamic Data Definition


Using SQL, the structure of a database can be changed and expanded dynamically, even
while users are accessing database contents. This is a major advance over static data
definition languages, which prevented access to the database while its structure was being
changed. SQL thus provides maximum flexibility, allowing a database to adapt to changing
requirements while online applications continue uninterrupted.
Chapter 1: Introduction 11

Client/Server Architecture
SQL is a natural vehicle for implementing applications using a distributed, client/server
architecture. In this role, SQL serves as the link between “front-end” computer systems

PART I
optimized for user interaction and “back-end” systems specialized for database management,
allowing each system to do what it does best. SQL also allows personal computers to
function as front-ends to network servers or to larger minicomputer and mainframe
databases, providing access to corporate data from personal computer applications.

Enterprise Application Support


The largest enterprise applications that support the daily operation of large companies and
organizations all use SQL-based databases to store and organize their data. In the 1990s, driven
by the impending deadline for supporting dates in the year 2000 and beyond (the so-called
“Y2K” problem), large enterprises moved en masse to abandon their homegrown systems and
convert to packaged enterprise applications from vendors like SAP, Oracle, PeopleSoft, Siebel,
and others. The data processed by these applications (orders, sales amounts, customers,
inventory levels, payment amounts, etc.) tends to have a structured, records-and-fields format,
which converts easily into the row/column format of SQL. By constructing their applications
to use enterprise-class SQL databases, the major application vendors eliminated the need to
develop their own data management software and benefited from existing tools and
programming skills. Because every major enterprise application requires a SQL-based database
for its operation, new sales of enterprise applications automatically generate “drag-along”
demand for new copies of database software.

Extensibility and Object Technology


The major challenge to SQL’s continued dominance as a database standard has come from
the emergence of object-based programming through languages such as Java and C++, and
from the introduction of object-based databases as an extension of the broad market trend
toward object-based technology. SQL-based database vendors have responded to this
challenge by slowly expanding and enhancing SQL to include object features. These “object/
relational” databases, which continue to be based on SQL, have emerged as a more popular
alternative to “pure object” databases and have perpetuated SQL’s dominance through the
last decade. The newest wave of object technology, embodied in the XML standard and web
services architectures, once again created a crop of “XML databases” and alternative query
languages to challenge SQL in the early 2000s. But once again, the major vendors of SQL-
based databases responded by adding XML-based extensions, meeting the challenge and
securing SQL’s continuing importance. History suggests that this “extend and integrate”
approach will be successful in warding off new challenges in the future as well.

Internet Database Access


With the exploding popularity of the Internet and the World Wide Web, and their
standards-based foundation, SQL found a new role in the late 1990s as an Internet data
access standard. Early in the development of the Web, developers needed a way to retrieve
and present database information on web pages and used SQL as a common language for
database gateways. More recently, the emergence of three-tiered Internet architectures with
distinct thin client, application server, and database server layers, has established SQL as
the standard link between the application and database tiers. The role of SQL in multitier
12 Part I: An Overview of SQL

architectures is now beginning to extend beyond the back-end database layer, to include
data caching and real-time data management in or near the application tier.

Java Integration (JDBC)


A major area of SQL development over the last five to ten years has been the integration of
SQL with Java. Seeing the need to link the Java language to existing relational databases,
Sun Microsystems (the creator of Java) introduced Java Database Connectivity (JDBC), a
standard API that allows Java programs to use SQL for database access. JDBC received a
further boost when it was adopted as the data access standard within the Java2 Enterprise
Edition (J2EE) specification, which defines the operating environment provided by most of
the leading Internet application servers. In addition to the role of Java as a programming
language from which databases are used, many of the leading database vendors have also
announced or implemented Java support within their database systems, allowing Java to be
used as a language for stored procedures and business logic within the database itself. This
trend toward integration between Java and SQL will ensure the continued importance of
SQL in the new era of Java-based programming.

Open Source Support


One of the newer important developments in the computer industry is the emergence of
an “open source” approach to building complex software systems. With this approach, the
source code that defines the operation of a software system is open and freely available,
and many different programmers can contribute to it, adding features, fixing bugs, enhancing
its functionality, and providing support for its use. This community of programmers,
potentially spread across thousands of different organizations and around the globe, with
some coordination becomes the engine that drives the further development of the technology.
Open source software is generally available at very low prices (or free), adding to its appeal.
Several successful open source SQL-based databases have been built in the last decade, and
one of these, MySQL, is a standard component of the most popular open source “stack” of
software—the LAMP stack—which also includes Linux, the Apache web server, and the PHP
scripting language. The widespread availability of free SQL-based open source databases has
exposed SQL to an even broader range of programmers, continuing to build its popularity.

Industry Infrastructure
Perhaps the most important factor contributing to the growing importance of SQL is the
emergence of an entire computer industry infrastructure based on SQL. SQL-based
relational database systems are an important part of this infrastructure. Enterprise
applications that use SQL and require a SQL-based database are another important part, as
are reporting tools, data entry tools, design tools, programming tools, and a host of other
tools that simplify the use of SQL. A large pool of experienced SQL programmers is a critical
part of the infrastructure. Another important part is the training and support services that
surround SQL and help to create and perpetuate SQL expertise. An entire subindustry has
emerged around SQL consulting, optimization, and performance-tuning. All parts of this
infrastructure tend to reinforce one another and to contribute to the ongoing success of the
other parts. Simply stated, to solve data management problems, the easiest, lowest-risk,
lowest-cost solution is almost always a solution based on SQL.
CHAPTER
2
A Quick Tour of SQL

B
efore we dive into the details of SQL, it’s a good idea to develop an overall
perspective on the language and how it works. This chapter contains a quick tour of
SQL that illustrates its major features and functions. The goal of the quick tour is not
to make you proficient in writing SQL statements; that’s the goal of Part II of this book.
Rather, by the time you’ve finished this chapter, you will have a basic familiarity with the
SQL and an overview of its capabilities.

A Simple Database
The examples in this quick tour are based on a simple relational database for a small
distribution company. The database, shown in Figure 2-1, stores the information needed to
implement a small order-processing application. You will find instructions for creating the
sample database in Appendix A, so you can try these queries yourself as you read.
Specifically, it stores the following information:

• The customers who buy the company’s products


• The orders placed by those customers
• The salespeople who sell the products to customers
• The sales offices where those salespeople work

This database, like most others, is a model of the “real world.” The data stored in the
database represents real entities—customers, orders, salespeople, and offices. Each different
kind of entity has a separate table of data. For example, in the SALESREPS table, each
salesperson is represented by one row, and each column holds one type of information
about salespeople, such as their name or the sales office where they are assigned. Database
requests that you make using the SQL parallel real-world activities, as customers place,
cancel, and change orders; as you hire and fire salespeople; and so on. Let’s see how you
can use SQL to manipulate data.

13
14 Part I: An Overview of SQL

FIGURE 2-1 A simple relational database

Retrieving Data
First, let’s list the sales offices, showing the city where each one is, its office number, and its
year-to-date sales. The SQL statement that retrieves data from the database is called SELECT.
This SQL statement retrieves the data you want:

SELECT CITY, OFFICE, SALES


FROM OFFICES;

CITY OFFICE SALES


------------ ------- ------------
Denver 22 $186,042.00
New York 11 $692,637.00
Chicago 12 $735,042.00
Atlanta 13 $367,911.00
Los Angeles 21 $835,915.00
Chapter 2: A Q u i c k To u r o f S Q L 15

The SELECT statement asks for three pieces of data—the city, the office number, and the
amount of sales—for each office. It also specifies that all of this data comes from the
OFFICES table, which stores data about sales offices. The results of the query appear, in

PART I
tabular form, immediately after the request. Note that the formatting of the query results
will vary from one SQL implementation to another.
The SELECT statement is used for all SQL queries. For example, here is a query that lists
the names and year-to-date sales for each salesperson in the database. It also shows the
quota (sales target) and the office number where each person works. In this case, the data
comes from the SALESREPS table.

SELECT NAME, REP_OFFICE, SALES, QUOTA


FROM SALESREPS;

NAME REP_OFFICE SALES QUOTA


-------------- ----------- ------------ ------------
Bill Adams 13 $367,911.00 $350,000.00
Mary Jones 11 $392,725.00 $300,000.00
Sue Smith 21 $474,050.00 $350,000.00
Sam Clark 11 $299,912.00 $275,000.00
Bob Smith 12 $142,594.00 $200,000.00
Dan Roberts 12 $305,673.00 $300,000.00
Tom Snyder NULL $75,985.00 NULL
Larry Fitch 21 $361,865.00 $350,000.00
Paul Cruz 12 $286,775.00 $275,000.00
Nancy Angelli 22 $186,042.00 $300,000.00

The NULL values for Tom Snyder represent missing or unknown data. He is new to the
company and has not yet been assigned to a sales office or been given a sales quota. However,
he has already made some sales. The data in his row of query results shows this clearly.
SQL also lets you ask for calculated results. For example, you can ask SQL to calculate
the amount by which each salesperson is over or under quota:

SELECT NAME, SALES, QUOTA, (SALES – QUOTA)


FROM SALESREPS;

NAME SALES QUOTA (SALES–QUOTA)


-------------- ------------ ------------ --------------
Bill Adams $367,911.00 $350,000.00 $17,911.00
Mary Jones $392,725.00 $300,000.00 $92,725.00
Sue Smith $474,050.00 $350,000.00 $124,050.00
Sam Clark $299,912.00 $275,000.00 $24,912.00
Bob Smith $142,594.00 $200,000.00 –$57,406.00
Dan Roberts $305,673.00 $300,000.00 $5,673.00
Tom Snyder $75,985.00 NULL NULL
Larry Fitch $361,865.00 $350,000.00 $11,865.00
Paul Cruz $286,775.00 $275,000.00 $11,775.00
Nancy Angelli $186,042.00 $300,000.00 –$113,958.00

The requested data (including the calculated difference between sales and quota for
each salesperson) once again appears in a row/column table. Perhaps you would like to
focus on the salespeople whose sales are less than their quotas. SQL lets you retrieve that
16 Part I: An Overview of SQL

kind of selective information very easily, by adding a mathematical comparison to the


previous request:

SELECT NAME, SALES, QUOTA, (SALES – QUOTA)


FROM SALESREPS
WHERE SALES < QUOTA;

NAME SALES QUOTA (SALES–QUOTA)


-------------- ------------ ------------ -------------
Bob Smith $142,594.00 $200,000.00 –$57,406.00
Nancy Angelli $186,042.00 $300,000.00 –$113,958.00

You can use the same technique to list large orders in the database and find out which
customer placed the order, which product was ordered, and in what quantity. You can also
ask SQL to sort the orders based on the order amount:

SELECT ORDER_NUM, CUST, PRODUCT, QTY, AMOUNT


FROM ORDERS
WHERE AMOUNT > 25000.00
ORDER BY AMOUNT;

ORDER_NUM CUST PRODUCT QTY AMOUNT


---------- ----- -------- ---- -----------
112987 2103 4100Y 11 $27,500.00
113069 2109 775C 22 $31,350.00
112961 2117 2A44L 7 $31,500.00
113045 2112 2A44R 10 $45,000.00

Summarizing Data
SQL not only retrieves individual pieces of data from the database, but it also can
summarize the database contents. What’s the average size of an order in the database? This
request asks SQL to look at all the orders and find the average amount:

SELECT AVG(AMOUNT)
FROM ORDERS;

AVG(AMOUNT)
------------
$8,256.37

You could also ask for the average order size for a particular customer:

SELECT AVG(AMOUNT)
FROM ORDERS
WHERE CUST = 2103;

AVG(AMOUNT)
-----------
$8,895.50
Chapter 2: A Q u i c k To u r o f S Q L 17

Finally, let’s find out the total value of the orders placed by each customer. To do this,
you can ask SQL to group the orders together by customer number and then total the orders
for each customer:

PART I
SELECT CUST, SUM(AMOUNT)
FROM ORDERS
GROUP BY CUST;

CUST SUM(AMOUNT)
----- ------------
2101 $1,458.00
2102 $3,978.00
2103 $35,582.00
2106 $4,026.00
2107 $23,132.00
2108 $7,255.00
2109 $31,350.00
2111 $6,445.00
2112 $47,925.00
2113 $22,500.00
2114 $22,100.00
2117 $31,500.00
2118 $3,608.00
2120 $3,750.00
2124 $3,082.00

Adding Data to the Database


You also use SQL to add new data to the database. For example, suppose you just opened a
new Western region sales office in Dallas, with target sales of $275,000. Here’s the INSERT
statement that adds the new office to the database, as office number 23:

INSERT INTO OFFICES (CITY, REGION, TARGET, SALES, OFFICE)


VALUES ('Dallas', 'Western', 275000.00, 0.00, 23);

1 row inserted.

Similarly, if Mary Jones (employee number 109) signs up a new customer, Acme
Industries, this INSERT statement adds the customer to the database as customer number
2125 with a $25,000 credit limit:

INSERT INTO CUSTOMERS (COMPANY, CUST_REP, CUST_NUM, CREDIT_LIMIT)


VALUES ('Acme Industries', 109, 2125, 25000.00);

1 row inserted.

You may have noticed that the SQL engine returned feedback (1 row inserted) to tell
you that the statements worked. The exact wording and formatting of this feedback will
vary from one SQL implementation to another.
18 Part I: An Overview of SQL

Deleting Data
Just as the SQL INSERT statement adds new data to the database, the SQL DELETE statement
removes data from the database. If Acme Industries decides a few days later to switch to a
competitor, you can delete Acme’s customer information from the database with this statement:

DELETE FROM CUSTOMERS


WHERE COMPANY = 'Acme Industries';

1 row deleted.

And if you decide to terminate all salespeople whose sales are less than their quotas,
you can remove them from the database with this DELETE statement:

DELETE FROM SALESREPS


WHERE SALES < QUOTA;

2 rows deleted.

Updating the Database


You can use SQL to modify data that is already stored in the database. For example, to
increase the credit limit for First Corp. to $75,000, you would use the SQL UPDATE
statement:

UPDATE CUSTOMERS
SET CREDIT_LIMIT = 75000.00
WHERE COMPANY = 'First Corp.';

1 row updated.

The UPDATE statement can also make many changes in the database at once. For
example, this UPDATE statement raises the quota for all salespeople by $15,000:

UPDATE SALESREPS
SET QUOTA = QUOTA + 15000.00;

8 rows updated.

Protecting Data
An important role of a database is to protect the stored data from access or modification by
unauthorized users. For example, suppose your assistant, Mary, has a database account but
has not been previously authorized to insert data about new customers into the database.
This SQL statement grants her that permission:

GRANT INSERT
ON CUSTOMERS
TO MARY;

Privilege granted.
Chapter 2: A Q u i c k To u r o f S Q L 19

Similarly, the following SQL statement gives Mary permission to update data about
customers and to retrieve customer data with the SELECT statement:

PART I
GRANT UPDATE, SELECT
ON CUSTOMERS
TO MARY;

Privilege granted.

If Mary is no longer allowed to add new customers to the database, this REVOKE statement
will disallow it:

REVOKE INSERT
ON CUSTOMERS
FROM MARY;

Privilege revoked.

Similarly, this REVOKE statement will revoke all of Mary’s privileges to access or modify
customer data in any way:

REVOKE ALL
ON CUSTOMERS
FROM MARY;

Privilege revoked.

Creating a Database
Before you can store data in a database, you must first define the structure of the data.
Suppose you want to expand the sample database by adding a table of data about the
products your company sells. For each product, the data to be stored includes the
following:

• A three-character manufacturer ID code


• A five-character product ID code
• A product description of up to 30 characters
• The price of the product
• The quantity currently on hand

This SQL CREATE TABLE statement defines a new table to store the products’ data:

CREATE TABLE PRODUCTS


(MFR_ID CHAR(3),
PRODUCT_ID CHAR(5),
DESCRIPTION VARCHAR(30),
PRICE DECIMAL(9,2),
QTY_ON_HAND INTEGER);

Table created.
Another Random Document on
Scribd Without Any Related Topics
The Project Gutenberg eBook of The Wyoming
Military Establishment. A History of the
Twenty-fourth Regiment of Connecticut Militia
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: The Wyoming Military Establishment. A History of the


Twenty-fourth Regiment of Connecticut Militia

Author: Charles Tubbs

Release date: September 26, 2019 [eBook #60361]


Most recently updated: October 17, 2024

Language: English

Credits: Produced by Graeme Mackreth and The Online


Distributed
Proofreading Team at http://www.pgdp.net (This file
was
produced from images generously made available by
The
Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK THE WYOMING


MILITARY ESTABLISHMENT. A HISTORY OF THE TWENTY-FOURTH
REGIMENT OF CONNECTICUT MILITIA ***
EARLY MAP OF WYOMING AND LACKAWANNA VALLIES.

The Wyoming Military Establishment.

A HISTORY

—OF THE—

TWENTY-FOURTH REGIMENT
—OF—
CONNECTICUT MILITIA.

An Address

before

The Tioga Point Historical Society

delivered December 3rd, 1901, by

Hon. CHARLES TUBBS,


Honorary Member Tioga Point Historical Society.
Corresponding Member Wyoming Historical & Geological Society.

Athens, Penna.
1903.

LIEUTENANT LEBBEUS TUBBS,


PRIVATE SAMUEL TUBBS,
LIEUTENANT-COLONEL GEORGE DORRANCE.
TO THE MEMORY OF THESE, MY ANCESTORS,
MEMBERS OF THE TWENTY-FOURTH REGIMENT,
I DEDICATE THIS STUDY
OF COLONIAL AND REVOLUTIONARY EVENTS,
IN WHICH THEY PERFORMED A PART.
ILLUSTRATIONS.
Map of Wyoming Valley,

Lazarus Stewart's Block House,

Forty Fort in 1778,

Pittston Fort,

Wyoming Monument,
The plates from which the above illustrations were printed were
kindly loaned by the Wyoming Historical and Geological Society.

Athens Gazette,
Athens, Pa.

The Wyoming Military Establishment.


Alsace-Loraine is a conquered province. The flag of Germany floats
over it. Within the memory of most of us it was an integral part of
France. At the time of the conquest, no heart of all its people went
willingly to the side of the victor.
We are met to-day in Pennsylvania. Yet for years, in the eighteenth
century the soil beneath our feet, and five thousand square miles of
adjacent territory, inside the present limits of Pennsylvania, was an
integral part of the State of Connecticut. It was settled by
Connecticut people, was under Connecticut institutions, was
governed by Connecticut laws. It was a Connecticut town; it was a
Connecticut county; had a judge, a sheriff, other officers, and sent
representatives to the Connecticut legislature.
Pennsylvania made conquest of it. No heart of all the people of this
Connecticut town went willingly to the side of the victor. The
Alsatians were no more stunned, at being forcibly wrenched from
their allegiance to the flag they loved, than were the Connecticut
people who had settled a town of their own in the heart of
Pennsylvania.
How did this cataclysm befall? I will tell you. It all came of the
ignorance or carelessness of a King. In 1620 King James I. of
England granted a Charter to the Plymouth company for the ruling of
New England in America. The charter covered North America from
the fortieth to the forty-eighth degrees of north latitude, and from
the Atlantic to the Pacific oceans. The Plymouth Company proceeded
to sub-divide its territory. In 1631 it granted a charter to the
Connecticut Colony which covered the space between the forty-first
and forty-second degrees of north latitude "and from the
Narragansett river on the east to the South Sea on the west
throughout the main lands." The South Sea was the Pacific Ocean.
In 1662 King Charles II. gave a new charter to Connecticut
confirming the act of the Plymouth Company. Nineteen years later
this same King in the grant of Pennsylvania to William Penn, included
a portion of the same territory, already given by him to Connecticut.
The ignorance or carelessness of King Charles, in due time bore a
rich harvest of strife and bloodshed. Under the Connecticut charter
(which was the older) my ancestors, and perhaps yours, came into
this valley of the Susquehanna, and sat themselves down. Under the
Pennsylvania charter (which was the younger) came sheriffs, and
armed men, to drive them off. On the tongues of men this disputed
section was known as Wyoming. In the statute book it is called
Westmoreland.
Having explained how the Connecticut people under a claim of right,
built up a government within the present boundaries of
Pennsylvania, I have said all I desire to say on that subject. It
explains how a part of what is now Pennsylvania was really a part of
Connecticut in the last years of our Colonial history, and in the first
years of our history as an independent nation—from 1774 to 1783.
This Twenty-fourth regiment of Connecticut Militia was organized on
that part of the soil of Pennsylvania which was known as the
Wyoming region, and in that region it performed its deeds, and lived
its organic life.
I am aware that this explanation is quite unnecessary. I am aware
that the Society that listens to me contains many descendants of the
men who made the history I am about to relate. I am aware that the
great-grandchildren of Captains Bidlack, Franklin, Spaulding, and
Whittlesey here reside. I know that descendants of the Buck, Gore,
Mathewson, Satterlee, Stevens and Tozer families abound in this old
town. A writer who knows your community better than I do could
mention others.
I have been attracted to the history of the Twenty-fourth regiment of
Connecticut Militia because in all the histories it has received so little
attention. Mr. Chapman, in his "Sketch of the History of Wyoming,"
(1830) says: "The whole body of the citizens was formed into a
militia." (p. 102). He does not say it was a regiment nor designate it
by its number. Col. Stone, in his work entitled, "Wyoming and its
History," (1841), alludes to it in the phrase, "a regiment of militia
being organized," (p. 202), but does not state its number nor give it
further attention. Charles Miner, in his "History of Wyoming in a
Series of Letters," (1845), gives many facts, but notices only six of
the ten companies of which the regiment was composed and details
only the organization of those companies as it was in 1775. George
Peck, in his "Wyoming: its history, stirring incidents, and romantic
adventures," (1858), devotes to it a passing allusion in the words, "a
regiment of militia having been established." (p. 28). Stewart Pearce
does not allude to the Twenty-fourth regiment at all in his "Annals of
Luzerne," (1866), but does mention five of its companies. (p. 34)
Steuben Jenkins, in his "Historical Address at the Monument,"
(1878), mentions its existence (p. 17), and at another place
enumerates seven of its companies. (p. 34) Horace Edwin Hayden,
in his monograph entitled, "Major John Garret; a forgotten hero of
the Massacre of Wyoming," (1895) explains the existence of the
regiment, credits it with nine companies, and gives the changes of
the officers made in 1777.
In my judgment, the services of this regiment were of more
importance than have been accorded them by the historians. I shall
seek to arrange those already well known, into a comprehensive
whole, to show their relation to other events, and to add some facts
not hitherto brought to light.
The Wyoming community was isolated in its situation. It was seventy
miles from it to the settlements on the Delaware; it was sixty miles
to Fort Augusta; to the north and to the west, was a howling
wilderness. This wilderness was filled with a savage Indian
population. A continual fight was waged with the proprietaries of
Pennsylvania.
The settlement, which became permanent, was begun in 1769. It
was a self-governing community. It kept a record of its official acts.
In 1772 it was voted, "That each and every settler should provide
himself with a flint lock and ammunition, and continue to guard
around the threatened plantations until further notice."[1] That was
the first step—individual action, every man defend his own castle.
This did not prove effectual. Organization was needed. That was the
second step in the evolution. It took time to bring it about—perhaps
a year. At a meeting of the inhabitants held March 22, 1773, it was
voted: "That the Comtee of settlers be Desired to send to the several
towns or to their Comtee. Requiring them to Call all the Inhabitants
in Each of ye said towns to meet on Thursday Next at five a Clock in
ye afternoon of sd Day in some Convenient place in sd town, and
that they then Chouse one Person in Each of sd towns as an officer
to muster them, & so that all are oequipt according to Law with fire
arms, and ammunition, and that they Chuse two Sergants & a Clerk
& that the said Chieff officer is Hereby Commanded & Directed to
Call ye Inhabitants together once in 14 Days for ye future until this
Company orders otherwise & that in case of an allarm or ye
appearance of an Enemy he is Directed to call ye sd Inhabitants
together & stand for ye Defense of ye sd towns & Settlements
without further orders."[2] In speaking of these preparations Miner
says: "If the splendid uniform, the glittering bayonet, the evolution
rapid and precise, with the imposing band of music, did not grace
their trainings, there was yet upon the ground the strong banded old
French musket, the long duck shooting piece, and more efficient
than either the close drawing rifle, little known in New England, but
becoming familiar on the banks of the Susquehanna." Trainings once
in fourteen days! They certainly believed in the strenuous life. Those
trainings were not holidays. They were serious preparation for
impending warfare.
In January. 1774, the Wyoming settlements which had grown to a
population of 1922 souls,[3] were taken official notice of by the
legislature of Connecticut which incorporated them as the town of
Westmoreland. Wyoming and Westmoreland may henceforth be
regarded as interchangeable terms.
The next step in the evolution of the military establishment had its
origin at the second town meeting after the incorporation, which was
held on the 12th day of April, 1774. The town, by a vote, applied for
the establishment of a regiment.[4] For some reason the legislature
was slow to act. It may have been for the want of a representative
in the law making body. The town, however, did not neglect to keep
itself in a state of preparedness. They kept everlastingly at it. At the
fourth town meeting held that year "Votes were passed to form
themselves into companies in a military way,"[5] each district in
Westmoreland to be a company and Zebulon Butler, Esq., Major
Ezekiel Pierce and Mr. John Jenkins were appointed a committee to
repair to the several districts and lead each company to a choice of
officers.
From this it is clear that the officers were chosen by a vote of the
men in each company. The subsequent "establishment" of the rank
of officers by the Connecticut Assembly was but a ratification of
what had already been done by vote of the men.
It was more than a year after the action of the town meeting asking
for the legal organization of a regiment before the legislature acted
upon the subject. At May session, 1775, it enacted "That the town of
Westmoreland shall be one entire regiment distinguished and called
by the name of the Twenty-fourth regiment and shall be under the
same rules and orders, and have the same powers, privileges and
advantages as other regiments of this Colony by law have."[6]
One of these advantages was the promise of six pence for half day
training and twelve pence for whole day training, and this to be paid
out of the Colony treasury.
The regiment was assigned to the sixth brigade, Connecticut State
Militia, commanded by Brig. Gen. Oliver Wolcott. The organization
was begun by the "establishment" of the regimental officers at the
same session. Zebulon Butler was made Colonel; Nathan Denison,
Lieutenant Colonel; William Judd, Major.[7]
Zebulon Butler, the newly elected colonel, born at Lynne. Conn.,
1731, was no novice in the military service. In the French and Indian
war he was Ensign in Captain Andrew Ward's 2 company of the 4
Conn. Regt. in 1755-6-7. He was Lieutenant in Captain Timothy
Mather's company of the 3 Regt. in 1758. He was Captain in the 4th
and 1st regiments in 1759, 1760 and 1761.[8] He had served seven
enlistments. The territorial range of his service extended from Crown
Point on the north to Havana on the south. When elected Colonel his
home was in Wilkes-Barre.
Nathan Denison, the newly elected Lieutenant Colonel, born in
Conn., 1741, had seen service in the French and Indian war as a
private in Col. Eleazar Fitch's 3d Conn. Regt. His services extended
from May to November, 1758. His home was in Kingston.
Speaking of these two men Miner says: "Nature never formed two
excellent men in more distinct contrast. Butler polished in manner,
quick in perception, vehement and rapid in execution: Denison, plain
though courteous, slow to speak, as careful to consider, cool and
firm, if not alert in action. They were the two great and
acknowledged leaders in Westmoreland."[9]
William Judd, the newly elected Major, does not seem to have had
any military experience outside of the militia.
The accessible records are silent about the progress made with the
regiment during the summer of 1775, but it is fair to assume that
the newly commissioned field officers did not neglect their duty in
perfecting their organization and in training their men.
At the October session of the Connecticut legislature the election of
the officers of nine of the companies were ratified. They were as
follows:[10]
First (Lower Wilkes-Barre) Company, Stephen Fuller, Captain; John
Garret, Lieutenant; Christopher Avery, Ensign.
Second (Kingston) Company, Nathaniel Landon, Captain; George
Dorrance, Lieutenant; Asahel Buck, Ensign.
Third (Plymouth) Company, Samuel Ransom, Captain; Perrin Ross,
Lieutenant; Asaph Whittlesey, Ensign.
Fourth (Pittston) Company, Solomon Strong, Captain; Jonathan
Parker, Lieutenant; Timothy Keyes, Ensign.
Fifth (Hanover) Company, William McKarachan, Captain; Lazarus
Stewart, Jr., Lieutenant; Silas Gore, Ensign.
Sixth (Upper Wilkes-Barre) Company, Rezin Geer, Captain; Daniel
Gore, Lieutenant; Matthias Hollenback, Ensign.
Seventh (Exeter) Company, Stephen Harding, Captain; Elisha Scovill,
Lieutenant; John Jenkins, Jr., Ensign.
Eighth (Lackaway) Company, Eliab Farnham, Captain; John Shaw,
Lieutenant; Elijah Winters, Ensign.
Ninth (Up the River) Company, James Secord, Captain; John De Pui,
Lieutenant; Rudolph Fox, Ensign.
Some of these officers had seen service as soldiers in the French and
Indian War.[11] Captain Eliab Farnham, of the Lackaway Company,
had done a tour of duty lasting twenty-five weeks in 1758 in Capt.
Nathan Whiting's Company, 2d Conn. Regt. Lieut. Elisha Scovill had
served 32 weeks in 1759 in Capt. Amos Hitchcock's Company in the
seventh Connecticut regiment.
Lieutenant Jonathan Parker had served 34 weeks in 1761 in the third
company of the First Conn. Regt. commanded by Major David
Baldwin.
The citizen liable to serve in the Connecticut militia was a man,
between 16 and 50 years of age, but for specified reason many were
exempt from the service.[12]
There was an almost immediate call for all the skill and ability of the
newly commissioned officers not only in the training field, but in the
arena of actual war. The Governor of Pennsylvania had made up his
mind to completely destroy the Connecticut settlement at Wyoming.
Wyoming was within the Pennsylvania county of Northumberland of
which William Cook was Sheriff. William Cook, under pretense of
serving sundry writs at Wyoming, took with him an armed force of
700 men under the command of Colonel William Plunket. He called it
a "posse."
This force left Northumberland early in December, 1775, marching
up the west side of the river over the almost impassable roads. The
supplies for the expedition were loaded into boats. Progress was
slow, as the boats had to be propelled against the current,
encumbered as it often was at that season of the year by floating
ice. December 20th, Col. Plunket was at Nescopeck Creek, nineteen
miles below the south eastern extremity of the valley. His progress
now was closely watched by scouts. On Saturday, the 23d he arrived
at Harvey's landing, one-fourth of a mile below the mouth of
Harvey's Creek, where he landed, unloaded his boats, and
encamped for the night.
What preparation had been made to receive the invader? On this
same Saturday Col. Zebulon Butler mustered the newly formed
Twenty-fourth regiment. He also collected all the old men and boys
who did not belong to the ranks of the regiment and armed them
the best he could. In number, his force thus made up, was about
four hundred. The two armies spent the night within a half mile of
each other. From this point Col. Butler sent out a flag to Col. Plunket,
in charge of Lieutenant Garret, inquiring the object of the invasion.
Col. Plunket's reply was that he came on a peaceful errand, simply to
serve some Pennsylvania writs at Wyoming.
On Sunday morning. Col. Butler left Ensign Mason F. Alden[13] with
18 men on the ground where he had spent the night. At the same
time he sent Capt. Lazarus Stewart[14] of the Hanover Company,
with 20 men across the river to the east side above the Nanticoke
Falls to prevent the enemy from landing, should they attempt to do
so. He then, with the main body of his force, retreated about one
mile up the river to a place where a natural defence existed. This
consisted of a ridge of rocks projecting about one-half a mile south
easterly from the Shawanese mountain to the river. Near the river it
was 1 or 2 feet high, but as it ran back toward the mountain it was
of great height. Wherever there were breaks in this natural rampart,
Butler's men filled in the space with logs and stones. Behind this
breastwork the Twenty-fourth regiment and its co-operating forces
were stationed. About 11 o'clock Alden and his men became
conscious that the enemy was moving, and they withdrew. They
announced the approach of the enemy to Col. Butler and joined him
behind the fortification. When the enemy advanced it was met with
a fusilade of shots along the whole line, killing one man, wounding
others and throwing the whole force into the utmost confusion.
Without firing a shot Col. Plunket withdrew to the camp at Harvey's
Creek.
Late in the afternoon the enemy brought two of its boats by land
from Harvey's landing above the Nanticoke Falls. At night fall they
were loaded with soldiers and rowed across the river. When they
attempted to land they were fired upon by Captain Stewart and his
men, who lay in ambush upon the bank, killing one man, and
wounding others. The attempt to land was given up and the boats
and their cargoes floated down through the rapids and were safely
moored at Harvey's landing. Thus ended the events of the day.
On Christmas Day Col. Plunket renewed the attack on the
breastwork. He divided his forces into two divisions. One division
assailed the fortification in front, while the other attempted a
flanking movement on Col. Butler's right. This was promptly met and
repelled. The battle lasted nearly all day, but the enemy, baffled at
all points, finally withdrew. The invasion known by Col. Plunket's
name was at an end. Eight or ten men on each side were killed and
many wounded.[15]
The battle with Plunket had made the officers and men of the
regiment painfully conscious of their lack of equipment. Powder!
How could they get powder? Offer a reward for it? That was what
they did at a town meeting, March 10, 1776—two and a half months
after the battle. "Voted that the first man that shall make fifty weight
of good salt peter, in this town, shall be entitled to ten pounds lawful
money, to be paid out of the town treasury."[16]
Patriotism and this bounty no doubt produced an effect, as witness
the following: "Mrs. Bethiah Jenkins says. The women took up their
floors, dug out the earth, put it in casks, and ran water through it.
Then took ashes in another cask and made lye—mixed the water
from the earth with weak lye, boiled it, set it out to cool, and the salt
peter rose to the top. Charcoal and sulphur were then used, and
powder produced."[17]
In May, 1776, John Jenkins, representative to the legislature,
obtained leave for the selectmen to erect a powder mill in
Westmoreland, but I can not learn that any mill was ever built.[18]
In July of the same year the Council of Safety at Hartford "Voted
that the Selectmen of Westmoreland may receive at Messrs. Elderkin
& Wales mill, not exceeding 200 pounds of gun powder: they to
account to the Colony therefor at the price of 5s, 4d per lb."[19]
Col. Butler, in a letter to Roger Sherman, dated August 6, 1776,
speaks of being in want of arms, "as those 80 guns taken from our
people at Warrior Run have not been returned."[20]
The Continental Congress the next year undertook to aid in
supplying these wants, as witness the following action April 11:
"Resolved, that 175 fire arms, either musquets or rifles, 200 wt.
powder, 800 wt. lead, and 500 flints be sent to the town of
Westmoreland, on the east branch of the Susquehanna river, to the
care of Colonel Nathan Denison, to be used by the malitia there, for
the defense of the said town, if necessary: the arms to be returned
when the service there will admit of it."[21]
I am telling the story of a regiment whose fortunes were profoundly
affected by the Revolutionary War. The men of which it was
composed were intense rebels against the authority of England.
Therefore when the Congress on the 23d of August, "Resolved, That
two companies on the Continental Establishment be raised in the
town of Westmoreland"[22] it responded with an enlistment of 82
men in each company. Captain Samuel Ransom, Lieutenant Perrin
Ross, Ensigns Asahel Buck and Matthias Hollenbeck, with others,
were elected as officers. I mention these because they were officers
in the Twenty-fourth regiment. The men were all taken from the
ranks of the Twenty-fourth regiment. Twenty other men in the
summer of 1776 also enlisted under Lieutenant Obadiah Gore, to
serve in a New York State regiment under Colonel Weisner, as well
as ten more men to serve under Captain Strong. Our regiment thus
lost of its most robust men, 194 in the Summer of 1776, who
enlisted into the Continental Army.
While this depletion was going on the town assigned additional
duties to the field officers at a meeting held August 28. "Voted ye
field officers of ye regiment of this town be appointed a committee
to view the most suitable places to build forts for ye defense of sd
town, and determine on some particular spot or place in each district
for the purpose, and mark out the same."[23] Think for a moment of
the work imposed on this Committee! Think of the large territory to
be gone over, the consideration of reasons for or against any
particular location. Think of the work imposed on the men who were
to build the forts.

STEWART'S BLOCK HOUSE.


There were some old forts like Forty Fort in Kingston, and Fort
Brown in Pittston, that were repaired and enlarged, but in other
districts there were no suitable works of the kind and accordingly
new sites were selected, and the proposed works laid out on the
ground. Such was the case in Wilkes-Barre, Plymouth and Exeter. In
Lower Pittston and Hanover, block houses were recommended and
built. The work of repairing and building the forts ran through the
years 1776, 1777 and was not completed until 1778.
Before closing the regimental history for 1776 I wish to mention the
advent of the tenth company into its ranks, representing the train
bands of the Districts of Huntington and Salem, of which Frethias
Wall was elected Lieutenant and John Franklin, Jr., Ensign, at the
October session of the legislature.[24] I have not seen this company
assigned its proper place in the regiment in any of the histories. Of
this company John Franklin, Jr., was ultimately to become the
Captain and Stoddart Bowen the Lieutenant.
In December, 1776, a supplement to the militia law was enacted by
the Connecticut legislature, by which the age limit of those liable to
serve was extended to persons from 50 to 60 years of age, and
many theretofore exempt were brought into the service. These
persons were to be formed into companies to be called the "Alarm
List," to elect their own officers and to be attached to already
existing regiments.[25]
Under this act two companies were formed in Wyoming in 1777—
one on the east side of the river, of which William Hooker Smith was
elected Captain, one on the west side of the river of which James
Bidlack, Sr., was elected Captain. These became attached to the
Twenty-fourth regiment.
In popular speech these old men and exempts were called
"Reformadoes." Under this Act the Colonels of regiments were given
authority "to assemble in martial array and put in warlike posture,"
the men under their command in case of invasion.
In the Spring of 1777 the regiment took up a new duty. It was the
duty of sending out scouting parties.[26] The Indians and Tories up
the river were showing activity by occasionally capturing some one,
and making a prisoner of him. Lieut. Asa Stevens, of the Kingston
Company, went on a scouting expedition and brought in five
suspected persons. Ensign John Jenkins, Jr., of the Exeter Company,
led a scouting party up as far as Wyalusing, and was himself
captured and three other men. Captain Asaph Whittlesey, of the
Plymouth Company, led a scouting party up as far as Standing
Stone. In January, 1778, Capt. Eliab Farnham, of the Lackaway
Company, captured 18 tories[27] that had been disturbing his
vicinage and sent them to Hartford under the escort of Lieut.
Jonathan Haskell. The legislature declared that these persons should
be treated as prisoners of war. This action was necessary, because
the frontiersmen held that the prisoners ought to be hanged as
cattle thieves. In May, 1778, Nathan Denison memorialized the
legislature to be reimbursed as Colonel of the Twenty-fourth
regiment, in sending out detachments as scouts and for guards
during 1776, 1777 and 1778. The prayer of his memorial was
granted.[28]
I must refer in this place to a further nominal depletion of the
regiment. By act of Congress March 16, 1778, it was resolved to
raise another Company of Continental troops at Westmoreland. The
efforts to do this was at least partially successful and Dethic Hewit
was elected Captain of the new company. In the same resolution it
was provided that the new organization should be under the
command of the field officers of the Twenty-fourth regiment.[29]
The enlistment of this company reduced the strength of the
regiment. It transferred the service of the men from the state to the
service of the United States. It did not, however, withdraw them
from the Wyoming Valley.
I will here explain the changes in the officers of the regiment. Under
the militia laws of Connecticut there were two general muster days
in the year—first Monday of May, first Monday of October. On either
new officers could be elected to fill vacancies or for other reasons.
Able and ambitious men coveted and strove to become officers of
the regiment and of the companies. In the larger and stronger
companies the rivalry was great and the officers were in a continual
state of flux. In this way there were a large number of ex-officers.
The ex-officers retained their titles by courtesy. Once a captain,
always a captain. In the Wyoming histories, and upon the monument
erected on the battlefield, confusion results, from giving the courtesy
titles of ex-officers as much prominence as is given the titles of men
who were in commission, and exercised actual command. In view of
these and similar facts I have been to much pains to make the roster
of those in actual command accurate as it was in the last formation
of the regiment.[30]
I will first call attention to the changes in the regimental officers.
Colonel Zebulon Butler resigned to enter the Continental service
January 1, 1777. Lt. Col. Nathan Denison was promoted to be
colonel. This occasioned a vacancy in the office of lieutenant-colonel,
which was filled by the election of Lazarus Stewart, the famous
Captain of the Paxtang Rangers, who declined to accept, and
thereupon Major George Dorrance was promoted to that office in
Oct., 1777. Major William Judd resigned to enter the Continental
service, and his place was filled in May, 1777, by the promotion of
Lieut. George Dorrance and on his elevation to the Lt. Colonelcy,
Captain John Garret was elected Major in Oct., 1777.[31]
I have given a list of the Company officers as "established" at the
organization of the regiment. They underwent many changes as
heretofore indicated. I will give them as they existed in May, 1778,
when the last changes were made of which there is a record.[32]
This is a list of the Captains beginning with the first Company and
thus on through to the tenth. They were as follows: James Bidlack,
Jr., Aholiab Buck, Asaph Whittlesey, Jeremiah Blanchard, William
McKarachan, Rezin Geer, Stephen Harding, Eliab Farnham, Robert
Carr and John Franklin, Jr.
The Lieutenants were Lebbeus Tubbs, Elijah Shoemaker, Aaron
Gaylord, Timothy Keyes, Roswell Franklin, Daniel Gore, Elisha Scovil,
John Shaw, Nathan Kingsbury and Stoddart Bowen.
The Ensigns were: John Comstock, Asa Gore, William White,
Jeremiah Bigford, Titus Hinman, John Hagerman, John Jenkins, Jr.,
Elijah Winters, Rudolph Fox and Nathaniel Goss. John Jenkins, Jr., of
the Exeter company, probably should not be included as he had
recently been elected a lieutenant in the Continental Service. This
company had no Ensign in commission.
Some of these new officers had seen service in the old French war.
Lieutenant Lebbeus Tubbs had served two enlistments—one of 26
weeks in 1755, in Capt. Nicholas Bishop's company of the first Conn,
regiment—another in 1759 of 27 weeks in Capt. John Pitkin's
company of the Fourth Conn. Regt.[33]
In the latter year he was in the expedition sent out for the reduction
of Crown Point. Ensign William White served 35 weeks in 1756 in
Capt. Samuel Champlin's Company in the First Conn, regiment.
Ensign Titus Hinman in 1755 served 32 weeks in Capt. Benjamin
Hinman's company in the Second Conn. regiment.
The Twenty-fourth regiment availed itself of other means of
becoming efficient. Two deserters from the British army—Abraham
Pike and Sergeant Boyd—were employed as drill masters, and spent
much time in putting the men through their evolutions.[34]
It had need of the skill of all its officers, of the efficiency of all its
men. While I have been talking about officers, important events
have been hastening toward a conclusion, on the northern border.
They now claim attention. Up to this time (1778) no murders had
been committed by the Indians. They now became frequent.
Scouting parties of the regiment were continually going out and
coming in. They heralded the approach of an invading army.
Premonitory signs of its coming had not been wanting.
It consisted of about 1,100 British soldiers, Indians and Tories, under
the command of Major John Butler.[35] This force had been gathered
at Kanadaseago and other points in Western New York. The time
was the month of June, when nature puts on her best apparel. It
approached Wyoming in boats. I can imagine the wild and weird
flotilla, tricked out in barbaric splendor, as it rounded Tioga Point,
and swept out into the broad waters of the Susquehanna, receiving
welcome reinforcements to its numbers as it passed Queen Esther's
flats and the meadows of Sheshequin. It landed above Wyoming in
Keeler's Eddy. It marched about twenty miles by land and was ready
to do its work.
What was the situation at Wyoming? What the preparation to receive
it? We have detailed the building of the forts; the establishment of
the regiment and its depletion from time to time to recruit the
Continental service. The forts were there—and the regiment—what
there was of it.
We left the enemy at the head of the valley. It signified its approach
by killing six men in Exeter on the 30th of June, 1778. On the first
day of July it seized Fort Wintermoot. This fort was occupied by
Elisha Scovil, lieutenant of the Exeter (7th) company and a few
patriotic men. The Wintermoots and other non-combatants in the
fort were Tories[36] and after making the best show of resistance he
could, Scovil capitulated. At Fort Jenkins, one mile above Fort
Wintermoot, were eight men, including Stephen Harding, Captain of
the 7th (Exeter) company. Resistance against such odds was useless
and it surrendered on the second of July, although the articles of
capitulation were dated on the first.[37] This disposes of one of the
companies of the Twenty-fourth regiment.
To the valley below a vague knowledge of what was happening was
communicated by scouts and by persons who had escaped when the
Hardings and Hadsells were killed on the 30th of June. Some
information was obtained by a reconnoisance in force on the first of
July.
In consequence the population gathered into the several forts on the
first and second days of July.
FORTY FORT IN 1778.
Of these, Forty Fort in Kingston was the largest and the strongest. In
it Col. Nathan Denison established his headquarters. He endeavored
to concentrate his regiment at this point. There were many obstacles
in the way. Captain Robert Carr's (9th) Up River company could not
be reached because of the proximity of the enemy. According to
Hollister, this Company was at Capouse Meadows (Scranton).[38]
Captain Eliab Farnham's (8th) Lackaway company was 70 miles away
and could not be reached on account of the distance. This company
did not learn of the invasion until it was over.[39] Thus these two
companies were unavailable. So far as adding to the force of lighting
men was concerned, they did not do it. Denison sent a messenger
express to Captain Franklin in Huntington, who dispatched
Lieutenant Stoddart Bowen with the first of his men who could be
gotten together. He sent another messenger to Wilkes-Barre.
Zebulon Butler, Lt. Col. of the third regiment of the Connecticut line
was then at Wilkes-Barre on furlough. Denison asked him to come to
Forty Fort. When there, by common consent, he assumed command
of all the forces.
Early in the afternoon of Friday, July 3d, the two Wilkes-Barre, the
Hanover, Plymouth, Kingston and part of the Huntington companies
were at the rendezvous mustering not more than 200 men. In
addition to these were Captain Hewit's company of Continental
Soldiers, some old men, young boys, and refugees from all sides,
who were willing to risk their lives, but did not belong to any military
organization. Perhaps 400 would be a fair estimate to put on the
whole number of fighting men. On the 2d and again on the 3d day
of July the enemy demanded the surrender of the Forts and all the
military forces in the Valley.
What shall be done? Great uncertainty existed, as to the strength
and intention of the enemy. Shall the force now in hand await the
coming of promised reinforcements?—the more complete
concentration of the regiment, the advance of the enemy? or shall
they march out and give battle? A council of war was held in which
the pros and cons were warmly debated. It was decided to give
battle.
"About three o'clock in the afternoon they marched from the fort, in
martial array, with the stars and stripes at their head, to the tune of
Saint Patrick's Day in the Morning, played on the fife by a true son of
Erin, and with drums beating."[40] They proceeded about three miles
in column when they formed a line of battle of about 500 yards
front. Capt. Dethic Hewit with his so-called regulars, was on the
extreme right, with Captain Bidlack next to him, and he joined by
Captain Geer. On the extreme left was Capt. Whittlesey and the
Salem detachment under Lieut. Bowen. Next to them was the
Hanover company under Captain Stewart (McKaracan having that
day resigned), and he was joined by Captain Buck, of Kingston. This
was the order in which the advance was made. It was made over a
plain that was grown up with brush—yellow pines, pitch pines and
scrub oak. These bushes could be seen over by a man, but were
high enough to conceal a skulking foe. The right rested on a rise of
ground near the river, and was led by Lieut. Col. Zebulon Butler,
aided by Major John Garret. The left was commanded by Col.
Nathan Denison, assisted by Lieut. Col. George Dorrance.
The enemy in front had the Tories in the center under Captains
Pawling and Hopkins and the British regulars on their extreme left
under Captain William Caldwell and Lieutenant Turney. On the
enemy's right were the Indians, under cover of the alders in a
swamp led by a Seneca Chief named Sayenqueraghta.[41]
The Americans advanced with spirit, the enemy purposely falling
back under fire for the distance of about a mile, until they came to a
cleared field. On the opposite side of this field was a log fence which
the British used as a breastwork, and from it poured in such a
severe fire that it checked the advance. Just at this point the Indians
with brandishing spears and demoniac yells, rushed out of the
swamp on the left, in which most of them lay concealed, enveloped
the left wing by superior numbers, and turned it in upon the right. In
the melee that ensued an effort was made to re-form it, so that it
would present a front to the enemy, but in the confusion occasioned
by the fierce onset of the enemy the orders were misunderstood and
the day was lost.
The men retreated in squads at first, firing as they gave ground, but
borne down by overwhelming numbers, the retreat became a rout,
and every man did the best he could to save himself. It was four
miles back to the fort. On the way some of the squads were
captured, some in pairs, some singly. The slaughter of captured men
by the Indians constitutes what is known in history as the Wyoming
Massacre. Some of the fugitives reached Forty Fort; some Wilkes-
Barre. Lieut. Col. Zebulon Butler escaped with his life. He and the
remnant of Hewit's regulars left the valley. They did not surrender.

PITTSTON FORT.
What of the Twenty-fourth Regiment? Col. Denison reached Forty
Fort alive. Lieut. Col. George Dorrance was mortally wounded. Major
John Garret was killed. The Captain of every company fell upon the
field, as also did three Lieutenants and three Ensigns. How many
men the regiment lost it is impossible to say, but from 200 to 300 of
those engaged on the American side were slain. The loss of the
enemy was from 40 to 80 men.
Early the next day, July 4, the British commander sent a detachment
across the river and demanded the surrender of Fort Brown, in
which the Pittston people assembled, under the command of Captain
Jeremiah Blanchard. The demand was complied with.[42] It is said
that this company failed to report at Forty Fort because the enemy
captured all the water craft along the river in its vicinity. This
disposes of one more of the companies of the Twenty-fourth
Regiment.
The same day the surrender of Forty Fort was demanded on terms
deemed reasonable under the circumstances. No means for further
resistance were at hand. After some negotiation articles of
capitulation were drawn up and signed.[43] Protection was promised
to persons and property. The fort was surrendered. Captain Franklin
had come up from Huntington, while the battle was in progress on
Abraham's Plains, with the remainder of his company and they were
included in the surrender[44], thus making six complete companies. I
have now accounted for the ten original companies of the regiment.
Captain William Hooker Smith's company of the "Alarm List" was in
the fort with the women and children at Wilkes-Barre, and Capt.
James Bidlack, Sr.'s company was in the fort on Garrison Hill in
Plymouth. These "Reformadoes" belonged to Col. Denison's
command.
The victors planned a spectacular entrance into Forty Fort. Massed in
columns of four upon the left, approached Major John Butler at the
head of his Rangers and Royal Greens; on the right came the Seneca
Chiefs, leading their warriors, streaked with paint, adorned with
feathers, and other picturesque barbaric ornaments. They were
preceded with waving banners, the screech of fife, and the roll of
drums. At a signal the gates were opened: in at the north gate
entered the Tories and British Provincials; at the south gate the
savages.[45]
This scene as it came down to me when a child, from the reported
words of a great grandmother who witnessed it, most profoundly
impressed my youthful imagination.
What occurred after the capitulation? By the terms of the surrender
protection was promised to persons and property. Regardless of the
terms, the Indians plundered individuals of the clothing on their
persons, pillaged the farm steads of everything movable, drove away
the live stock, destroyed the growing crops and burned the buildings
of the distressed inhabitants to the ground. Their commander could
not, or would not restrain them.
The result was that on the night following the battle, and on the two
or three succeeding days and nights, the 3,000 inhabitants of the
Wyoming Valley fled, some by boats and rafts down the river, but by
far the greater number through the wilderness, and over the
mountains to the settlements beyond. It was not a planned and
orderly hegira, in which provision was made for necessary wants,
but a hurried, hasty, precipitate flight, urged on to desperation by
every element of real and imaginary danger. Their houses, furniture,
household utensils, crops, flocks, farming implements, provisions,
papers, clothing, horses, wagons,—all left behind. And it was all
utterly destroyed or carried off. Of the delicate women and tender
children, not less than 200 perished by the way. In the battle, the
massacre, and the flight it is probable that 500 persons lost their
lives. In a memorial to the Connecticut legislature, the survivors
stated that their property losses amounted to 38,308 pounds, 13s.
[46]

In the Articles of Capitulation signed at Forty Fort was this: "Art. 7.


That the inhabitants Col. Denison capitulates for, together with
himself, do not take up arms during the present contest." Some
undoubtedly considered themselves bound by this article. Colonel
Denison for one is no longer heard of in our military annals,
although Westmoreland remained more than four years longer under
the jurisdiction of Connecticut. The Twenty-fourth regiment was
never reorganized. It was overwhelmed on the field of battle; it was
surrendered in sections, by the terms of four military conventions.
[47] Of this sort of glory it had a monopoly. As a regiment its story is
told.
On the other hand many of the men considered themselves absolved
from the terms above recited. The party that imposed the
conditions, did not themselves observe them. Lieut. Col. Zebulon
Butler, one month from the day of surrender, returned to the valley
at the head of some Continental soldiers and 40 militiamen and went
into garrison at Wilkes-Barrie. A muster roll of these men is extant.
Many of them were men who had been surrendered. Captain John
Franklin, with a company of Wyoming militia, went out in Hartley's
expedition the same year, and in Sullivan's expedition the next year,
and on other occasions.
In an upper chamber of this building is an original pay roll of one of
these companies. Many of its names are identical with those who
served in the Twenty-fourth regiment.
After the flight of the people from the valley the dead lay unburied
on the plain where they fell for nearly four months. On the twenty
second day of October a detail of thirty men was sent from the
garrison at Wilkes-Barre as a guard to protect those of the
inhabitants that had returned, in performing that solemn duty.[48]
A granite monument suitably inscribed now marks the place of
sepulchre. Engraved upon it is a very inaccurate list of those "slain in
battle" and of "survivors."
In this temple, dedicated to the Muse of the backward look, it may
be appropriate to inquire, What relation, if any, had these events to
the history of the times? The drama of the American Revolution held
the center of the stage. Did our regiment enact a part? An important
part. It triumphed mightily in its death. The tales of the butchery of
these captured citizen soldiers, the cries of those mothers and little
children, driven from their burning homes to the wilds of the forest,
were heard all over the civilized world. The execration of mankind
was visited upon a King, and a country, that employed savage allies
and paid them ten dollars apiece, in gold, for the scalps of human
beings.
It produced another effect. It called the attention of Washington and
the Congress to the imperative necessity of dealing a death blow, to
the Six Nation Confederacy of Indian barbarians. A year passed by.
The avengers of Wyoming darkened the waters that wash the shores
of your beautiful peninsula-they swarmed over the lands where we
are assembled to-night, they went forward, they did the work
assigned them; Wyoming was avenged.

WYOMING MONUMENT.
Permit me a word of review.
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like