A Guide To SQL Standard
A Guide To SQL Standard
A Guide to
the SQL Standard
A user's guide to
i
the standard database language SQL
Fachbereichsbibliothek Informatik
TU Darmstadt
C J. Date
with
Hugh Darwen
B 1 BL 1 0 T H E K
n ^ - co>| a"
kiventar-Nr.:
Sachgebiete:.
Standort:
%*\
i
re
ADDISON-WESLEY
An imprint of Addison-Wesiey Longman, Inc.
Reading, Massachusetts Harlow, England ^Menlo Park, California Berkeley, California
Don Mills, Ontario Sydney Bonn Amsterdam Tokyo Mexico City
Contents
PART I
INTRODUCTION
Introduction
-9
Data definition
11
Data manipulation
13
Cursor operations
16
Views
18
Security and integrity
20
Recovery and concurrency
22
Schemas and catalogs
23
Sessions and connections
25
xvi
Contents
PART II
SOME PRELIMINARIES
49
SQL-agents
49
SQL-connections
51
SQL-sessions
54
SQL-transactions
56
CHAPTER
6.1
6.2
6.3
6.4
41
41
29
6 / Binding Styles
Introduction
63
The module language
Embedded SQL
71
Direct SQL
74
63
63
79
81
79
Contents
7.3
7.4
7.5
7.6
Literals
84
Scalar operators and functions
Aggregate functions
92
Assignments and comparisons
85
95
99
8.1 Introduction
99
8.2 Domains
100
8.3 Base tables
103
109
Introduction
109
Single-row SELECT
110
INSERT
111
Searched UPDATE
113
Searched DELETE
114
Introduction
115
Cursors
116
Cursor-based manipulation statements
121
A comprehensive example (module version)
124
A comprehensive example (embedded SQL version)
Introduction
133
Join expressions
135
Table references
137
Unions, differences, and intersections
Table primaries
148
Select expressions
150
Derived table column names
161
115
128
133
144
Contents
Introduction
165
General remarks
167
Comparison conditions
168
BETWEEN and LIKE conditions
169
IN and MATCH conditions
171
ALL-or-ANY conditions
176
EXISTS conditions
176
UNIQUE conditions
177
A final remark
178
CHAPTER 13 / Views
13.1
13.2
13.3
13.4
165
179
Introduction
179
Data definition operations
}82
Data manipulation operations
184
The check option
187
Introduction
197
Domain constraints
200
General constraints
202
Base table and column constraints
204
Foreign keys
210
Deferred constraint checking
216
CHAPTER 15 / Security
i
15.1
15.2
15.3
15.4
15.5
15.6
197
Introduction
219
Authorization identifiers
220
Privileges and access rules
222
GRANT and REVOKE
224
The grant option
227
RESTRICT vs. CASCADE
228
219
Contents
CHAPTER
16.1
16.2
16.3
16.4
16.5
16.6
233
Introduction
233
Effect of nulls on scalar expressions
235
Effect of nulls on conditional expressions
239
Effect of nulls on table expressions
248
Effect of nulls on integrity constraints
253
A recommendation
257
Introduction
259
Datatypes
259
Literals
263
Time zones
265
Data conversion
270
Scalar operators and functions
Assignments and comparisons
259
272
276
Introduction
285
Properties of character strings
287
Character sets and collations
288
Datatypes
292
Literals
293
Scalar operators and functions
295
Assignments and comparisons
298
Character sets for identifiers
305
281
283
285
xx
Contents
309
Introduction
309
What is the problem?
312
Statement preparation and execution
SQL descriptor areas
322
Cursor operations
331
Session defaults
337
314
CHAPTER
339
341
22 / Exception Handling
347
350
353
Introduction
353
What is the problem?
355
CLI routines and parameters
357
CLI resources and related matters
361
Statement preparation and execution
365
CLI descriptor areas
366
Placeholders
369
Retrieval operations
372
Exception handling
376
A sample "SQLCLI.H" file
377
A sample CLI application
389
APPENDIXES
APPENDIX A / An SQL Grammar
A.I Introduction
395
A.2 Sessions, connections, and transactions
395
397
Contents
A.3
A.4
A.5
A.6
A.7
A.8
A.9
A.10
A.ll
A.12
Data definition
398
Modules
400
Data manipulation
401
Table expressions
402
Conditional expressions
403
Constraints
404
Dynamic SQL
405
Scalar expressions
406
GET DIAGNOSTICS
407
Miscellaneous
410
B.I
B.2
B.3
B.4
411
Introduction
411
Intermediate SQL
412
Entry SQL
414
SQLflagger
416
xxi
419
Introduction
419
Extensions
419
Incompatibilities
422
Deprecated features
425
427
D.I Introduction
427
D.2 The issues
429 /
APPENDIX E
E.I
E.2
E.3
E.4
E.5
E.6
E.7
E.8
E.9
Introduction
453
Overview
456
Routines, modules, and schemas
467
Type precedence
472
Subject routine determination
474
SQL control statements
476
Exception handling
483
External routines
487
Miscellaneous topics
491
453
xxii
Contents
Introduction
495
Data definition and manipulation
Functions and operators
502
Integrity
506
Security
507
Transactions
507
495
497
509
Index
513