SQL Engine Reference
SQL Engine Reference
disclaimer
trademarks
Btrieve, Client/Server in a Box, Pervasive, Pervasive Software, and the Pervasive Software
logo are registered trademarks of Pervasive Software Inc.
Built on Pervasive Software, DataExchange, MicroKernel Database Engine, MicroKernel Database
Architecture, Pervasive.SQL, Pervasive PSQL, Solution Network, Ultralight, and ZDBA are
trademarks of Pervasive Software Inc.
Microsoft, MS-DOS, Windows, Windows 95, Windows 98, Windows NT, Windows Millennium,
Windows 2000, Windows XP, Win32, Win32s, and Visual Basic are registered trademarks of
Microsoft Corporation.
NetWare and Novell are registered trademarks of Novell, Inc.
NetWare Loadable Module, NLM, Novell DOS, Transaction Tracking System, and TTS are
trademarks of Novell, Inc.
Sun, Sun Microsystems, Java, all trademarks and logos that contain Sun, Solaris, or Java, are
trademarks or registered trademarks of Sun Microsystems.
All other company and product names are the trademarks or registered trademarks of their
respective companies.
Copyright 2007 Pervasive Software Inc. All rights reserved. Reproduction, photocopying, or
transmittal of this publication, or portions of this publication, is prohibited without the express prior
written consent of the publisher.
This product includes software developed by Powerdog Industries. Copyright 1994 Powerdog
Industries. All rights reserved.
This product includes software developed by KeyWorks Software. Copyright 2002 KeyWorks
Software. All rights reserved.
This product includes software developed by DUNDAS SOFTWARE. Copyright 1997-2000
DUNDAS SOFTWARE LTD., all rights reserved.
This product includes software developed by the Apache Software Foundation
(http://www.apache.org/).
This product uses the free unixODBC Driver Manager as written by Peter Harvey
(pharvey@codebydesign.com), modified and extended by Nick Gorham (nick@easysoft.com), with
local modifications from Pervasive Software. Pervasive Software will donate their code changes to the
current maintainer of the unixODBC Driver Manager project, in accordance with the LGPL license
agreement of this project. The unixODBC Driver Danager home page is located at
www.unixodbc.org. For further information on this project, contact its current maintainer: Nick
Gorham (nick@easysoft.com).
A copy of the GNU Lesser General Public License (LGPL) is included on the distribution media for
this product. You may also view the LGPL at www.fsf.org/licensing/licenses/lgpl.html.
Contents
About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Who Should Read this Manual
Manual Organization . . . . . .
Conventions . . . . . . . . . . .
For More Information . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
xvii
.
.
.
.
SQL Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xviii
xix
xxi
xxii
1-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1-3
1-3
1-4
1-4
1-4
1-4
1-5
1-7
1-7
1-8
1-8
1-9
1-9
1-9
1-9
1-10
1-10
1-11
1-11
2-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2-2
2-2
2-6
2-7
2-9
2-9
2-9
2-12
2-14
2-15
iii
Contents
2-17
2-19
3-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-2
3-3
3-4
3-5
3-8
3-10
3-26
3-28
3-29
3-31
3-32
3-33
3-34
3-39
3-40
3-41
3-44
3-46
3-51
3-58
3-59
3-66
3-80
3-93
3-103
3-106
3-108
3-113
3-114
3-116
3-123
3-125
3-128
3-129
3-131
3-132
3-133
3-135
3-136
3-137
Contents
DROP USER . . . . . . . . . . . . . . .
DROP VIEW . . . . . . . . . . . . . . .
END . . . . . . . . . . . . . . . . . . . .
EXECUTE . . . . . . . . . . . . . . . .
EXISTS . . . . . . . . . . . . . . . . . .
FETCH . . . . . . . . . . . . . . . . . .
FOREIGN KEY . . . . . . . . . . . . . .
GRANT . . . . . . . . . . . . . . . . . .
GROUP BY . . . . . . . . . . . . . . . .
HAVING . . . . . . . . . . . . . . . . .
IF . . . . . . . . . . . . . . . . . . . . .
IN . . . . . . . . . . . . . . . . . . . . .
INSERT . . . . . . . . . . . . . . . . . .
JOIN . . . . . . . . . . . . . . . . . . .
LEAVE . . . . . . . . . . . . . . . . . .
LIKE . . . . . . . . . . . . . . . . . . . .
LOOP . . . . . . . . . . . . . . . . . . .
NOT . . . . . . . . . . . . . . . . . . . .
OPEN . . . . . . . . . . . . . . . . . . .
PARTIAL . . . . . . . . . . . . . . . . .
PRIMARY KEY. . . . . . . . . . . . . .
PRINT. . . . . . . . . . . . . . . . . . .
PUBLIC . . . . . . . . . . . . . . . . . .
RELEASE SAVEPOINT . . . . . . . . .
RESTRICT . . . . . . . . . . . . . . . .
REVOKE . . . . . . . . . . . . . . . . .
ROLLBACK . . . . . . . . . . . . . . .
SAVEPOINT . . . . . . . . . . . . . . .
SELECT (with into) . . . . . . . . . . .
SELECT . . . . . . . . . . . . . . . . .
SET ANSI_PADDING . . . . . . . . .
SET CACHED_PROCEDURES . . . .
SET DECIMALSEPARATORCOMMA
SET DEFAULTCOLLATE . . . . . . .
SET OWNER . . . . . . . . . . . . . .
SET PASSWORD . . . . . . . . . . . .
SET PROCEDURES_CACHE . . . . .
SET ROWCOUNT . . . . . . . . . . .
SET SECURITY . . . . . . . . . . . . .
SET TIME ZONE . . . . . . . . . . . .
SET TRUEBITCREATE . . . . . . . . .
SET TRUENULLCREATE . . . . . . .
SET . . . . . . . . . . . . . . . . . . . .
SIGNAL . . . . . . . . . . . . . . . . .
SQLSTATE . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-138
3-139
3-140
3-141
3-143
3-145
3-147
3-149
3-160
3-162
3-163
3-165
3-166
3-173
3-180
3-181
3-183
3-184
3-185
3-186
3-187
3-189
3-190
3-191
3-193
3-194
3-197
3-199
3-201
3-202
3-228
3-231
3-235
3-237
3-240
3-242
3-245
3-249
3-250
3-252
3-258
3-259
3-260
3-261
3-263
Contents
START TRANSACTION . . . .
UNION. . . . . . . . . . . . . .
UNIQUE . . . . . . . . . . . . .
UPDATE . . . . . . . . . . . .
UPDATE (positioned) . . . . .
USER . . . . . . . . . . . . . . .
WHILE . . . . . . . . . . . . . .
Grammar Element Definitions
Global Variables . . . . . . . . . . . .
Other Characteristics . . . . . . . . .
Temporary Files . . . . . . . . .
Working with Literal Values . .
Working with NULL Values . .
Working with Binary Data . . .
Creating Indexes. . . . . . . . .
Closing an Open Table . . . . .
Concurrency . . . . . . . . . . .
Comma as Decimal Separator .
OEM to ANSI Support . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-264
3-266
3-268
3-269
3-277
3-279
3-280
3-281
3-290
3-294
3-294
3-296
3-298
3-298
3-299
3-299
3-300
3-300
3-304
Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . .
4-1
vi
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4-2
4-3
4-3
4-3
4-3
4-5
4-5
4-5
4-5
4-6
4-6
4-6
4-6
4-8
4-8
4-8
4-8
4-9
Contents
Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5-2
5-4
5-6
5-8
5-9
5-9
5-14
5-16
5-16
5-17
5-17
5-20
5-21
6-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6-2
6-3
6-6
6-9
6-13
6-15
6-17
6-19
6-21
6-23
6-25
6-28
6-29
6-32
6-33
6-36
6-39
6-41
6-43
6-45
6-47
6-50
vii
Contents
Performance Reference . . . . . . . . . . . . . . . . . . . . . . . .
7-1
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A-1
viii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
A-2
A-5
A-6
A-8
A-9
A-10
A-11
A-11
A-11
A-12
Contents
DATETIME. . . . . . . . .
UNIQUEIDENTIFIER. . .
Representation of Infinity .
Legacy Data Types . . . . . . . .
Btrieve Key Data Types . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. A-13
. A-17
. A-19
. A-20
. A-21
B-1
System Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B-2
B-7
C-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. C-2
. C-4
. C-4
. C-19
D-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. D-2
. D-2
. D-3
. D-4
. D-6
. D-6
. D-6
. D-6
. D-12
. D-13
. D-13
E-1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
E-2
E-3
E-3
E-3
E-7
E-9
E-9
E-10
ix
Figures
3-1
Tables
1-1
1-2
1-3
1-4
1-5
1-6
1-7
1-8
1-9
1-10
1-11
1-12
1-13
1-14
1-15
1-16
1-17
1-18
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1-1
1-3
1-4
1-4
1-4
1-4
1-5
1-5
1-6
1-7
1-8
1-8
1-9
1-9
1-9
1-10
1-11
1-11
2-1
2-2
2-3
2-4
2-5
2-6
2-7
2-8
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2-3
2-7
2-8
2-9
2-14
2-15
2-16
2-17
3-1
3-2
3-3
3-4
3-5
3-6
3-7
3-8
3-9
3-10
3-11
3-12
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-52
3-70
3-95
3-117
3-122
3-151
3-152
3-155
3-167
3-175
3-175
3-175
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
xi
Tables
3-13
3-14
3-15
3-16
3-17
3-18
3-19
3-20
3-21
3-22
3-23
3-24
3-25
3-26
3-27
Loc Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Two-way Left Outer Join . . . . . . . . . . . . . . . . . . . .
Three-way Radiating Left Outer Join . . . . . . . . . . . . .
Three-way Chaining Left Outer Join . . . . . . . . . . . . .
Three-way Radiating Left Outer Join, Less Optimized . . . .
Special Characters . . . . . . . . . . . . . . . . . . . . . . . .
Permissions Removed with ALL Key Word by Object Type .
Addr Table . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Loc Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SELECT Statement with Cartesian JOIN . . . . . . . . . . .
Effect of TOP Clause on Cursor Types . . . . . . . . . . . .
Time/Date Functions with SET TIME ZONE Default . . . .
Time/Date Functions with SET TIME ZONE Specified . . .
Local to UTC Conversion Examples . . . . . . . . . . . . . .
Timestamp Data Type Examples. . . . . . . . . . . . . . . .
4-1
5-1
5-2
5-3
5-4
5-5
5-6
String Functions . . . . . .
Numeric Functions . . . .
Time and Date Functions.
System Functions . . . . .
Logical Functions . . . . .
Conversion Functions. . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 5-2
. 5-6
. 5-9
. 5-16
. 5-17
. 5-21
6-1
6-2
6-3
6-4
6-5
6-6
6-7
6-8
6-9
6-10
6-11
6-12
6-13
6-14
6-15
6-16
6-17
6-18
6-19
6-20
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 6-2
. 6-3
. 6-3
. 6-7
. 6-7
. 6-10
. 6-10
. 6-13
. 6-14
. 6-16
. 6-16
. 6-17
. 6-18
. 6-20
. 6-20
. 6-21
. 6-22
. 6-24
. 6-24
. 6-25
xii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 3-175
. 3-176
. 3-177
. 3-178
. 3-179
. 3-181
. 3-195
. 3-221
. 3-221
. 3-222
. 3-223
. 3-253
. 3-253
. 3-254
. 3-254
Tables
6-21
6-22
6-23
6-24
6-25
6-26
6-27
6-28
6-29
6-30
6-31
6-32
6-33
6-34
6-35
6-36
6-37
6-38
6-39
6-40
6-41
6-42
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6-26
6-28
6-28
6-30
6-30
6-32
6-33
6-34
6-36
6-37
6-39
6-40
6-42
6-42
6-44
6-44
6-45
6-46
6-47
6-48
6-50
6-50
A-1
A-2
A-3
A-4
A-5
A-6
A-7
A-8
A-9
A-10
A-11
A-12
A-13
A-14
A-15
A-16
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
A-2
A-5
A-10
A-13
A-14
A-14
A-16
A-17
A-19
A-20
A-21
A-30
A-31
A-32
A-33
A-35
B-1
C-1
C-2
C-3
xiii
Tables
C-4
C-5
C-6
C-7
C-8
C-9
C-10
C-11
C-12
C-13
C-14
C-15
C-16
C-17
C-18
C-19
C-20
C-21
C-22
C-23
C-24
C-25
C-26
C-27
C-28
C-29
C-30
C-31
C-32
C-33
C-34
C-35
C-36
C-37
C-38
C-39
C-40
C-41
C-42
C-43
C-44
C-45
C-46
C-47
C-48
xiv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. C-5
. C-5
. C-6
. C-8
. C-8
. C-9
. C-9
. C-9
. C-10
. C-11
. C-12
. C-12
. C-13
. C-13
. C-14
. C-14
. C-15
. C-15
. C-16
. C-17
. C-17
. C-18
. C-18
. C-19
. C-19
. C-20
. C-20
. C-21
. C-23
. C-23
. C-24
. C-24
. C-25
. C-26
. C-27
. C-28
. C-28
. C-29
. C-29
. C-30
. C-31
. C-32
. C-33
. C-33
. C-34
Tables
C-49
C-50
C-51
D-1
D-2
D-3
D-4
E-1
E-2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
D-3
D-4
D-8
D-11
xv
Tables
xvi
xvii
xviii
Manual Organization
This reference includes the following chapters:
xix
xx
Conventions
Unless otherwise noted, command syntax, code, and examples use
the following conventions:
Case
[ ]
< >
variable
...
::=
xxi
xxii
chapter
SQL Overview
An Overview of the Structured Query Language (SQL)
Tasks
Data Definition
Data Manipulation
Data Control
1-1
SQL Overview
The rest of this chapter briefly describes the SQL statements used in
each statement category. For detailed information about each
statement, refer to SQL Syntax Reference on page 3-1.
The following are the statement category overview sections found in
this chapter:
1-2
Creating,
You can create, modify, and delete tables from a database by
Modifying, and constructing SQL using the following statements:
Deleting Tables Table 1-2 Data Definition StatementsTables
CREATE
TABLE
ALTER TABLE
DROP TABLE
1-3
SQL Overview
Creating and
Deleting Views
You can create and delete views from a database by constructing SQL
using the following statements:
Table 1-3 Data Definition StatementsViews
Creating and
Deleting
Indexes
Creating and
Deleting
Triggers
CREATE VIEW
DROP VIEW
Deletes a view.
DROP INDEX
DROP TRIGGER
Deletes a trigger.
AFTER
Creating and
A stored procedure consists of statements you can precompile and
Deleting Stored save in the dictionary. To create and delete stored procedures,
construct statements using the following:
Procedures
1-4
DROP
PROCEDURE
Creating and
Deleting UserDefined
Functions
(UDF)
IF...THEN...ELSE
LEAVE
LOOP
WHILE
1-5
SQL Overview
1-6
CREATE
FUNCTION
DROP
FUNCTION
Retrieving Data All statements you use to retrieve information from a database are
based on the SELECT statement.
Table 1-10 Data Manipulation StatementsRetrieving Data
SELECT
When you create a SELECT statement, you can use various clauses to
specify different options. (See the entry for the SELECT statement in
ODBC Engine Reference on page 2-1 for detailed information
about each type of clause.) The types of clauses you use in a SELECT
statement are as follows:
1-7
SQL Overview
WHERE
GROUP
BY
HAVING
ORDER
BY
Modifying Data
You can add, change, or delete data from tables and views by issuing
statements such as the following:
Table 1-12 Data Manipulation StatementsModifying Data
INSERT
UPDATE
DELETE
Defining
Transactions
1-8
Creating and
Deleting Views
You can create and delete views by constructing SQL using the
following statements:
Table 1-13 Data Manipulation StatementsViews
Executing
Stored
Procedures
CREATE VIEW
DROP VIEW
Executing
System Stored
Procedures
Executing
Triggers
1-9
SQL Overview
in a secure database, the Master user of the database must use the
owner name in any GRANT statement to grant privileges on the
given table to any user, including the Master user.
The following sections briefly describe the SQL statements
associated with each of these tasks.
Enabling and
Disabling
Security
1-10
Enables or disables security for the database and sets the Master
password.
Creating and
Deleting Users
and Groups
Granting and
Revoking
Rights
You can create or delete users and user groups for the database by
constructing SQL using the following statements:
Table 1-17 Data Control StatementsGroups and Users
ALTER USER
CREATE USER
DROP USER
Delete a user.
ALTER GROUP
CREATE GROUP
DROP GROUP
GRANT LOGIN TO
REVOKE LOGIN
FROM
GRANT CREATETAB TO
REVOKE CREATETAB
FROM
1-11
SQL Overview
1-12
chapter
2-1
Versions of Metadata
The relational interface in Pervasive PSQL v10 supports two versions
of metadata, referred to as version 1 (V1) and version 2 (V2).
Metadata version is a property of the database that you specify when
you create a database. V1 metadata is the default. When you create a
database, you must specify V2 metadata if you want that version.
Metadata version applies to all data dictionary files (DDFs) within
that database. A single database cannot use some DDFs with V1
metadata and others with V2 metadata. DDFs from the two versions
cannot interact.
The database engine can, however, concurrently access multiple
databases and each database can use either V1 metadata or V2
metadata.
All databases created with Pervasive PSQL versions prior to Pervasive
PSQL v10 use V1 metadata. Databases created with Pervasive PSQL
v10 or later may use either metadata version depending on the
database settings.
Comparison of Metadata Versions
Version 2 metadata allows for many identifier names to be up to 128
bytes long. Refer to Limits/Conditions of Pervasive PSQL Features
on page 2-3 on page 2-3 for additional information. In addition, V2
metadata allows for permissions on views and stored procedures. See
Permissions on Views and Stored Procedures on page 3-153.
The data dictionary files (DDFs) for V2 metadata are named
differently than for V1. In many cases, the V2 DDFs contain
additional fields and changes to existing fields. See System Tables
on page C-1.
Conversion Utility
Pervasive PSQL includes a conversion utility, pvmdconv, to convert
V1 metadata to V2 metadata. See pvmdconv on page 8-40 in
Pervasive PSQL User's Guide.
Relational
The following table shows the limits or conditions that apply to
Interface Limits features of the relational interface.
2-2
Versions of Metadata
Limit or Condition
Metadata
V1
V2
300
8,000 bytes1
Columns in a table
1,536
300
Column name2
20 bytes
128 bytes
Column size
2 GB
Correlation name
limited by memory
Cursor name
18 bytes
Database name2
20 bytes
Database sessions
limited by memory
2-3
Limit or Condition
Metadata
V1
30 bytes
128 bytes
Group name2
30 bytes
128 bytes
Index name2
20 bytes
128 bytes
Key name2
20 bytes
V2
128 bytes
Label name
limited by memory
300
65,536
2 billion
Parameter name
126 bytes
Password2
8 bytes
128 bytes
Procedure name2
30 bytes
128 bytes
Referential integrity (RI) constraint
name
20 bytes
128 bytes
Representation of single quote
Result name
limited by memory
2-4
Versions of Metadata
Limit or Condition
Metadata
V1
V2
Savepoint name
limited by memory
1,600
64 KB
limited by memory
64 KB
Table name2
20 bytes
128 bytes
Table rows
2 billion
limited by memory
Trigger name2
20 bytes
128 bytes
User name2
30 bytes
128 bytes
VARCHAR column size
8,000 bytes1
Variable name
limited by memory
View name2
20 bytes
128 bytes
The maximum size of a CHAR or VARCHAR column that may be fully indexed is 255 bytes
See also Identifier Restrictions by Identifier Type on page 1-3 in Advanced Operations Guide.
2-5
Fully Qualified
Object Names
A fully qualified object name combines the name of the database and
the object using dot notation. For example, if you have a view named
myview in database mydbase, the fully qualified object name is
mydbase.myview.
Fully qualified object names need to be unique within a database. For
example, suppose in database mydbase, you name a table acctpay
and a user-defined function (or any other object) acctpay. The fully
qualified name is mydbase.acctpay, in which case Pervasive PSQL
does not know to which object the name refers.
2-6
DRIVER
ServerName
ServerDSN
TransportHint
PWD
ArrayFetchOn
2-7
UID
2-8
DSN
DRIVER
DBQ
A database name.
UID
PWD
ODBC Support
ODBC Support
ODBC Interface The relational interface supports the ODBC v3.51 specifications for
Core, Level 1, and Level 2 interface support levels.
Support
Exceptions to ODBC Interface Support
Core Level
SQL_BEST_ROWID
The relational interface uses unique indexes as the optimal set of
columns that identifies a row in the table.
When a new row is inserted into a table that includes an IDENTITY
column, the relational interface does not return the value assigned to
the IDENTITY column. You may determine the value for an
IDENTITY column through the use of the @@IDENTITY variable.
See @@IDENTITY on page 3-290.
Level 2
SQL_ROWVER
See SQL_BEST_ROWID above.
SQL_ATTR_LOGIN_TIMEOUT
Not supported
ODBC API
Support
The following table lists the ODBC API functions supported by the
relational interface and the ODBC support level.
Table 2-4 Interface-supported ODBC API Functions
ODBC Function
SQLAllocHandle
Core
SQLBindCol
Core
SQLBindParameter
Core
SQLBrowseConnect
Level 1
SQLBulkOperations
Level 1
SQLCancel
Core
2-9
2-10
ODBC Function
SQLCloseCursor
Core
SQLColAttribute
Core
SQLColumnPrivileges
Level 2
SQLColumns
Core
SQLConnect
Core
SQLCopyDesc
Core
SQLDataSources
Core
SQLDescribeCol
Core
SQLDescribeParam
Level 2
SQLDisconnect
Core
SQLDriverConnect
Core
SQLDrivers
Core
SQLEndTran
Core
SQLExecDirect
Core
SQLExecute
Core
SQLExtendedFetch
Core
SQLFetch
Core
SQLFetchScroll
Core
SQLForeignKeys
Level 2
SQLFreeHandle
Core
SQLFreeStmt
Core
SQLGetConnectAttr
Core
SQLGetCursorName
Core
SQLGetData
Core
SQLGetDescField
Core
ODBC Support
SQLGetDescRec
Core
SQLGetDiagField
Core
SQLGetDiagRec
Core
SQLGetEnvAttr
Core
SQLGetFunctions
Core
SQLGetInfo
Core
SQLGetStmtAttr
Core
SQLGetTypeInfo
Core
SQLMoreResults
Level 1
SQLNativeSql
Core
SQLNumParams
Core
SQLNumResultCols
Core
SQLParamData
Core
SQLPrepare
Core
SQLPrimaryKeys
Level 1
SQLProcedureColumns
Level 1
SQLProcedures
Level 1
SQLPutData
Core
SQLRowCount
Core
SQLSetConnectAttr
Core
SQLSetCursorName
Core
SQLSetDescField
Core
SQLSetDescRec
Core
SQLSetEnvAttr
Core
SQLSetPos
Level 1
2-11
Exceptions to
ODBC API
Support
ODBC Function
SQLSetStmtAttr
Core
SQLStatistics
Core
SQLTablePrivileges
Level 2
SQLTables
Core
See also Pervasive PSQL Data Types and Equivalent ODBC Data
Types on page A-2 for a list of supported ODBC data types.
SQLSpecialColumns
The relational interface uses unique indexes as the optimal set of
columns that uniquely identifies a row in the table. When a new row
is inserted, the relational interface does not return the values for
IDENTITY columns. You may determine the value for an
IDENTITY column through the use of the @@IDENTITY variable.
See @@IDENTITY on page 3-290.
SQLGetData
If your application calls SQLGetData to return data into an
SQL_C_NUMERIC structure, the ODBC standard specifies that the
SQL_DESC_SCALE field is set to zero and the
SQL_DESC_PRECISION field uses the driver-defined precision.
Pervasive PSQL use the values for scale and driver-defined precision
as defined in the metadata. Consider the following example, in
which scale is set to two.
2-12
ODBC Support
CREATE TABLE testnum (col1 NUMERIC(10,2))
INSERT INTO testnum VALUES (10.34)
SELECT * FROM testnum
Value
Description
aa
Major version
bb
Minor version
cccc
Build number
ddd
Point build
2-13
Example Value
SQL_DRIVER_NAME
W3ODBCCI.DLL
SQL_DRIVER_VER
10.00.0147 012
SQL_DRIVER_ODBC_VER
03.51
SQL_DBMS_NAME
Pervasive.SQL
SQL_DBMS_VER
10.00.0147 012
SQL_ODBC_VER
03.52.0000
SQL_ODBC_API_CONFORMANCE
SQL_OAC_LEVEL2
SQL_ODBC_INTERFACE_CONFORMANCE
SQL_OIC_LEVEL2
ODBC Attribute The relational interface provides ODBC v3.51 attribute support,
with the following exceptions.
Support
Exceptions to ODBC Attribute Support
Statement Attribute Support
2-14
Comments
SQL_ATTR_QUERY_TIMEOUT (0)
SQL_ATTR_METADATA_ID (10014)
ODBC Support
Comments
SQL_ATTR_ENABLE_AUTO_IPD (15)
SQL_ATTR_PARAM_BIND_TYPE (18)
Only
SQL_PARAM_BIND_BY_COLUMN is
supported.
ODBC
Descriptor
Field Support
fOption
Comments
SQL_ATTR_AUTO_IPD
SQL_ATTR_METADATA_ID
SQL_ATTR_CONNECTION_TIMEOUT
2-15
2-16
fOption
Comments
SQL_DESC_BIND_TYPE
SQL_DESC_ROWVER
Minimum
Core
Extended
ALTER TABLE
CREATE GROUP
CREATE INDEX
CREATE PROCEDURE
CREATE TABLE
CREATE TRIGGER
CREATE VIEW
DELETE (positional)
DELETE (searched)
DROP GROUP
DROP INDEX
DROP PROCEDURE
DROP TABLE
DROP TRIGGER
DROP VIEW
GRANT
2-17
Minimum
Core
Extended
REVOKE
SELECT (with into)
- approximate-numeric-literal
- between-predicate
- correlation-name
- date arithmetic
- date-literal
- exact-numeric-literal
- extended predicates
- in-predicate
- set-function
- time-literal
- timestamp-literal
Subqueries
2-18
UNION
SET SECURITY
UPDATE (positional)
UPDATE (searched)
Delimited
Identifiers in
SQL
Statements
2-19
2-20
chapter
3-1
Grammar Statements
The following pages describe the complete grammar for all
supported SQL grammar elements.
Note You can use the SQL Editor provided with Pervasive PSQL
3-2
Grammar Statements
ADD
Remarks
Use the ADD clause within the ALTER TABLE statement to specify
one or more column definitions, column constraints, or table
constraints to be added.
See Also
3-3
ALL
Remarks
Examples
If the ID value from Person does not equal any of the ID values in the
subquery result table, Pervasive PSQL includes the row from Person
in the final result table of the statement.
See Also
3-4
Grammar Statements
ALTER (rename)
The ALTER (rename) statement allows you to change the name of
indexes, user-defined functions, stored procedures, tables, triggers,
or views.
Syntax
| FUNCTION
| PROCEDURE
| TABLE
| TRIGGER
| VIEW
qualified-object-name ::= database-name.table-name.object-name
| database-name.object-name
| table-name.object-name
| object-name
database-name, table-name, object-name, new-object-name ::= user-defined name
Remarks
You cannot rename the following objects if they were created with a
version of Pervasive PSQL prior to Pervasive PSQL v9:
stored procedures
triggers
views.
In releases prior to Pervasive PSQL v9, the system table index on the
name of these objects was created as not modifiable. The indexes for
these objects are modifiable with release Pervasive PSQL v9 or
greater.
You can use database-name to qualify any object-type. However, if it
is used to qualify an INDEX or TRIGGER object, you must also
include table-name. You can use table-name to qualify only the
objects INDEX and TRIGGER.
The ALTER statement can rename an object in a database whether or
not ODBC is currently connected to that database. You must use
database-name to qualify object-type if the object resides in a
3-5
3-6
Grammar Statements
ALTER TRIGGER RENAME electronics.domestic.testtrig3 TO
new_customer
See Also
3-7
ALTER GROUP
The ALTER GROUP statement adds or removes a user account from
a group.
Syntax
user-name
]...
Remarks
Examples
3-8
Grammar Statements
The user account polly granger (with a name containing nonalphanumeric characters) is removed from the group developers.
3-9
ALTER TABLE
The ALTER TABLE statement modifies a table definition.
Syntax
| ADD table-constraint-definition
| ALTER [ COLUMN ] column-definition
| DROP [ COLUMN ] column-name
| DROP CONSTRAINT constraint-name
| DROP PRIMARY KEY
| MODIFY [ COLUMN ] column-definition
alter-option-list2 ::= PSQL_MOVE [ COLUMN ] column-name TO [ [ PSQL_
PHYSICAL ] PSQL_POSITION ] new-column-position | RENAME
COLUMN column-name TO new-column-name
column-definition ::= column-name data-type [ DEFAULT default-value-expression
] [ column-constraint [ column-constraint ]... [CASE (string) |
COLLATE collation-name ]
column-name ::= user-defined name
new-column-position ::=
integer
integer
3-10
Grammar Statements
| default-value-expression - default-value-expression
| default-value-expression * default-value-expression
| default-value-expression / default-value-expression
| default-value-expression & default-value-expression
| default-value-expression | default-value-expression
| default-value-expression ^ default-value-expression
| ( default-value-expression )
| -default-value-expression
| +default-value-expression
| ~default-value-expression
| ?
| literal
| scalar-function
| { fn scalar-function }
| USER
| NULL
default-literal ::= 'string'
| number
| { d 'date-literal' }
| { t 'time-literal' }
| { ts 'timestamp-literal' }
default-scalar-function ::= USER ( )
| NULL ( )
| NOW ( )
| CURDATE ( )
| CURTIME ( )
| CURRENT_DATE ( )
| CURRENT_TIME ( )
| CURRENT_TIMESTAMP ( )
| CONVERT ( )
column-constraint ::= [ CONSTRAINT constraint-name ] col-constraint
constraint-name ::= user-defined-name
col-constraint ::= NOT NULL
| UNIQUE
3-11
| referential-delete-action [ referential-update-action ]
referential-update-action ::= ON UPDATE RESTRICT
referential-delete-action ::= ON DELETE CASCADE
| ON DELETE RESTRICT
collation-name ::= 'string' | user-defined-name
table-constraint-definition ::= [ CONSTRAINT constraint-name ] table-constraint
table-constraint ::= UNIQUE (column-name [ , column-name ]... )
Remarks
3-12
Grammar Statements
when you want to use a USING clause to change the data file path
name for a table.
You cannot use this keyword on a bound database.
IN DICTIONARY is allowed on CREATE and DROP TABLE, in
addition to ALTER TABLE. IN DICTIONARY affects dictionary
entries only, no matter what CREATE/ALTER options are specified.
Since Pervasive PSQL allows multiple options (any combination of
ADD, DROP, ADD CONSTRAINT, and so on), IN DICTIONARY is
honored under all circumstances to guarantee only the DDFs are
affected by the schema changes.
The error Table not found results if you query a detached table or
a table that does not exist. If you determine that a table exists but you
receive the Table not found error, the error resulted because the
data file could not be opened. This indicates a detached table. (Tables
that exist in the DDFs only (the data file does not exist) are called
detached entries. These tables are inaccessible via queries or other
operations that attempt to open the physical underlying file.)
You may verify whether a table really exists by using SQLTables or
directly querying the Xf$Name column of X$File:
SELECT * FROM X$File WHERE Xf$Name = 'table_name'
The SELECT statement returns the Xf$Loc value, which is the name
of the physical file for the table. Combine the name with a data path
defined for the database to get the complete path to the file.
It is possible for a detached table to cause confusion, so the IN
DICTIONARY feature must be used with extreme care. It is crucial
that it should be used to force table definitions to match physical
files, not to detach them. Consider the following examples, assuming
that the file test123.btr does not exist. (USING is explained below, in
the next subtopic.)
CREATE TABLE t1 USING 't1.btr' (c1 INT)
ALTER TABLE t1 IN DICTIONARY USING 'test123.btr'
If you then attempt to SELECT from t1, you receive an error that the
table was not found. Confusion can arise, because you just created
the tablehow can it not be found? Likewise, if you attempt to
DROP the table without specifying IN DICTIONARY, you receive
3-13
the same error. These errors are generated because there is no data
file associated with the table.
Whenever you create a relational index definition for an existing
Btrieve data file (for example, by issuing an ALTER TABLE statement
to add a column definition of type IDENTITY), Pervasive PSQL
automatically checks the Btrieve indexes defined on the file to
determine whether an existing Btrieve index offers the set of
parameters requested by the relational index definition. If an existing
Btrieve index matches the new definition being created, then an
association is created between the relational index definition and the
existing Btrieve index. If there is no match, then Pervasive PSQL
creates a new index definition and, if IN DICTIONARY is not
specified, a new index in the data file.
USING
3-14
Grammar Statements
specified with relative paths, are relative to the first Data Path as
defined in the Named Database configuration. (If you use IN
DICTIONARY, the file name does not have to relative to the first
data location.)
Root-based relative paths are also allowed. For example,
assuming that the first data path is D:\mydata\DEMODATA,
Pervasive PSQL interprets the path name in the following
statement as D:\TEMP\TEST123.BTR.
CREATE TABLE t1 USING '\temp\test123.btr' (c1 int)
3-15
You must use either a simple file name or a relative path in the
USING clause. If you specify a relative path, Pervasive PSQL
interprets it relative to the first data file path associated with the
database name.
The USING clause can be specified in addition to any other standard
ALTER TABLE option. This means columns can be manipulated in
the same statement that specifies the USING path.
If you specify a data file name that differs from the data file name
currently used to store the table data and you do not specify IN
DICTIONARY, Pervasive PSQL creates the new file and copies all of
the data from the existing file into the new file. For example, suppose
person.mkd is the current data file that holds the data for table
Person. You then alter table Person using data file person2.mkd, as
shown in the statement above. The contents of person.mkd are
copied into person2.mkd. Person2.mkd then becomes the data file
associated with table Person and database operations affect
person2.mkd. Person.mkd is not deleted, but it is not associated with
the database any more.
The reason for copying the data is because Pervasive PSQL allows all
other ALTER TABLE options at the same time as USING. The new
data file created needs to be fully populated with the existing tables
data. The file structure is not simply copied, but instead the entire
contents are moved over, similar to a Btrieve BUTIL -CREATE and
BUTIL -COPY. This can be helpful for rebuilding an SQL table, or
compressing a file that once contained a large number of records but
now contains only a few.
Note ALTER TABLE USING copies the contents of the existing
data file into the newly specified data file, leaving the old data file
intact but unlinked.
WITH REPLACE
3-16
Grammar Statements
the specified file name. The existing file is always overwritten as long
as the operating system allows it.
WITH REPLACE affects only the data file, it never affects the DDFs.
The following rules apply when using WITH REPLACE:
If you must change the data type of a primary or foreigh key column,
you can do so by dropping the constraint, changing the data type of
the column, and re-adding the constraint. Keep in mind that you
must ensure that all associated key columns remain synchronized.
For example, if you have a primary key in table T1 that is referenced
by foreign keys in tables T2 and T3, you must first drop the foreign
keys. Then you can drop the primary key. Then you need to change
3-17
all three columns to the same data type. Finally, you must re-add the
primary key and then the foreign keys.
The ANSI standard includes the ALTER keyword. Pervasive PSQL
allows both keywords (ALTER and MODIFY) in the ALTER TABLE
statement (the keyword COLUMN is optional):
ALTER
ALTER
ALTER
ALTER
TABLE
TABLE
TABLE
TABLE
t1
t1
t1
t1
MODIFY c1 INTEGER
ALTER c1 INTEGER
MODIFY COLUMN c1 INTEGER
ALTER COLUMN c1 INTEGER
3-18
Grammar Statements
existing columns or for a new column after adding it. You can move
a column logically and physically.
Type of Move
Result
Logical
Physical
Note Once you move columns logically, that order becomes the
3-19
returns status code 88. Ensure that you execute all data definition
statements before executing data manipulation statements.
For example, the following stored procedure fails and returns status
code 88 because the INSERT statement has table t1 open, which
prevents the ALTER TABLE statement from obtaining an exclusive
lock.
CREATE PROCEDURE proc1() AS
BEGIN
CREATE TABLE t1(c1 INT,c2 INT,c3 INT);
INSERT INTO t1 VALUES (123,345,678);
ALTER TABLE t1 PSQL_MOVE c3 to 1;
END;
RENAME COLUMN
3-20
Grammar Statements
ON DELETE CASCADE
The following statement adds two integer columns col1 and col2 to
the Class table.
ALTER TABLE class(ADD col1 INT, ADD col2 INT)
The following statement drops col1 and col2 from the Class table.
ALTER TABLE class(DROP col1, DROP col2)
This example adds an integer column col3 and drops column col2 to
the Class table
ALTER TABLE class(ADD col3 INT, DROP col2 )
The following example creates a primary key using the default key
name PK_ID on the Faculty table.
ALTER TABLE Faculty(ADD PRIMARY KEY(ID))
3-21
The following example drops the primary key in the Faculty table.
Because a table can have only one primary key, you cannot add a
primary key to a table that already has a primary key defined. To
change the primary key of a table, delete the existing key then add the
new primary key.
ALTER TABLE Faculty(DROP PRIMARY KEY)
Before you can drop a primary key from a parent table, you must
drop any corresponding foreign keys from dependent tables.
The following example adds a new foreign key to the Class table. The
Faculty_ID column is defined as a column that does not include
NULL values. You cannot create a foreign key on a Nullable column.
ALTER TABLE Class ADD CONSTRAINT Teacher FOREIGN KEY
(Faculty_ID) REFERENCES Faculty (ID) ON DELETE RESTRICT
The following example adds a foreign key to the Class table without
using the CONSTRAINT clause. In this case, a foreign key constraint
is generated internally to reference the primary key (ID) of Faculty.
The column listed in the REFERENCES clause is optional. Columns
listed in the REFERENCES clause can be included, if you choose, to
3-22
Grammar Statements
3-23
3-24
Grammar Statements
Instead, you must issue two separate ALTER statements. The first to
rename c1 to c2; the second to rename col2 to c1.
ALTER TABLE t1 (RENAME COLUMN c1 TO c2)
ALTER TABLE t1 (RENAME COLUMN col2 TO c1)
See Also
3-25
ALTER USER
The ALTER USER statement changes the name or password of a user
account.
Syntax
Remarks
Examples
3-26
Grammar Statements
The following examples show how to change the password for a user
account.
ALTER USER pgranger WITH PASSWORD Prvsve1
3-27
ANY
Remarks
The ANY keyword works similarly to the ALL keyword except that
Pervasive PSQL v10 includes the compared row in the result table if
the condition is true for any row in the subquery result table.
Examples
See Also
3-28
Grammar Statements
AS
Remarks
Examples
The keyword AS is optional when used for table aliases as in this next
example. When you use the AS clause on a table name in a FROM
clause, you can reference the name in a WHERE, ORDER BY,
GROUP BY, and HAVING clause.
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_Id
FROM Person AS p, class AS c
WHERE p.Id = c.Faculty_Id
ORDER BY c.Faculty_Id
You can rewrite this query without using the AS clause in the FROM
clause as follows.
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_Id
FROM Person p, class c
WHERE p.Id = c.Faculty_Id
ORDER BY c.Faculty_Id
3-29
Once you establish a table alias, do not intermix the table name and
its alias in a WHERE clause. The following does not work:
SELECT DISTINCT c.Name, p.First_Name, c.Faculty_Id
FROM Person p, class c
WHERE Person.Id = c.Faculty_Id
ORDER BY c.Faculty_Id
See Also
3-30
Grammar Statements
BEGIN [ATOMIC]
Remarks
Examples
See Also
3-31
CALL
Remarks
Examples
See Also
3-32
Grammar Statements
CASCADE
Remarks
See Also
3-33
CASE (expression)
A CASE expression returns a value. CASE expression has two
formats:
Simple When/Then:
CASE case_value_expression
WHEN when_expression THEN then_expression [...]
[ ELSE else_expression ]
END
Searched When/Then:
CASE
WHEN search_expression THEN then_expression [...]
[ ELSE else_expression ]
END
Arguments
case_value_expression
3-34
Grammar Statements
Examples
Course Title
Prerequisites
Art 101
Drawing I
None
Art 102
Drawing II
Art 203
Drawing III
Art 102
Art 204
Drawing IV
Art 203
Art 305
Sculpture
Art 101
3-35
Art 406
Modern Art
None
Art 407
Baroque Art
Art 305
Course Title
Prerequisites
Art 101
Drawing I
None
Art 102
Drawing II
Art 203
Drawing III
Art 102
Art 204
Drawing IV
Art 203
Art 305
Sculpture
Art 101
Art 406
Modern Art
Art 407
Baroque Art
3-36
Grammar Statements
WHEN scholarship = 1 THEN 'Scholastic'
WHEN citizenship <> 'United States' THEN 'Foreign
Study'
WHEN (date_of_birth >= '1960-01-01' AND date_of_
birth <= '1970-01-01') THEN 'AJ-44 Funds'
ELSE 'NONE'
END
AS 'Funding Program' FROM Person ORDER BY last_name
First_Name
Funding Program
Abad
Alicia
NONE
Abaecherli
David
Foreign Study
Abebe
Marta
Foreign Study
Abel
James
AJ-44 Funds
Abgoon
Bahram
Foreign Study
Abken
Richard
NONE
Abu
Austin
Foreign Study
Abuali
Ibrahim
AJ-44 Funds
Acabbo
Joseph
NONE
Acar
Dennis
Foreign Study
3-37
See Also
3-38
Grammar Statements
CASE (string)
Remarks
Examples
The following example shows how you add a column to the Student
table with the CASE keyword.
ALTER TABLE Student ADD Name char(64) CASE
See Also
3-39
CLOSE
Remarks
Syntax
CLOSE cursor-name
cursor-name ::= user-defined-name
Examples
See Also
3-40
Grammar Statements
COALESCE
The COALESCE scalar function takes two or more arguments and
returns the first nonnull argument, starting from the left in the
expression list.
Syntax
Arguments
expression
Restrictions
Invalid:
COALESCE()
Invalid:
COALESCE (NULL, NULL, NULL)
3-41
3-42
Grammar Statements
Chart Element
Description
Types can be used directly in COALESCE function. The result type is that of operand 2.
Types can be used directly in COALESCE function. The result type is that of operand 1.
blank cell
Types are not compatible. The operands cannot be used directly in COALESE. An explicit
CONVERT is required.
3-43
COMMIT
The COMMIT statement signals the end of a logical transaction and
converts temporary data into permanent data.
Syntax
COMMIT [ ]
Remarks
Examples
3-44
Grammar Statements
WHERE E.Student_ID = B.Student_ID);
COMMIT WORK;
START TRANSACTION;
UPDATE Billing B
SET Amount_Paid = 0
WHERE Student_ID IN
(SELECT DISTINCT E.Student_ID
FROM Enrolls E, Billing B
WHERE E.Student_ID = B.Student_ID);
COMMIT WORK;
See Also
3-45
CREATE DATABASE
The CREATE DATABASE statement creates a new database. Any user
logged in to a database can issue the statement. (The user must also
have permissions at the operating system to create files in the
specified location.)
Syntax
Remarks
3-46
Grammar Statements
Dictionary Path
Dict-path-name specifies where the dictionary files (DDFs) reside on
physical storage. The data files are also placed in this same location
when you use the CREATE TABLE on page 3-80 statement or create
tables using Pervasive PSQL Control Center (PCC). See Dictionary
Location on page 3-21 in Pervasive PSQL User's Guide.
Data Path
Data-path-name specifies a possible location of the data files for the
database (see Note below). You can specify multiple path names by
delimiting them with a semicolon.
Data-path-name can be any path that is valid from the database
engine's point of view, not from the calling application's perspective.
The location specified must already exist. The CREATE DATABASE
statement does not create directories.
Omit data-path-name if you want to use the same location for the
data files as for the dictionary files. You may also specify the same
location by passing an empty string for data-path-name. For
example, specifying DATA_PATH '' indicates an empty string for the
data path.
Note If you create tables using the CREATE TABLE statement or
with PCC, the data files are placed in the first dict-path-name
specified. If no dict-path-names are specified, data files are
created in the dict-path-name location.
Data-path-name is useful if you are creating tables through the
Distributed Tuning Interface (DTI). The DTI function
PvAddTable allows you to specify where you want the data files
located. See PvAddTable() on page 2-21 in the SDK book
Distributed Tuning Interface Guide.
Referential Integrity
By default, the database engine enforces referential integrity. If you
specify the NO_REFERENTIAL_INTEGRITY clause, then any
triggers and referential integrity defined in the database are not
enforced.
3-47
3-48
Grammar Statements
Mixed. This policy has aspects of both of the other policies. Users
log in using their operating system user names and passwords,
but a users access rights to the data are governed by user
permissions set up in the database.
Security Model
DBSEC_AUTHENTICATION
DBSEC_AUTHORIZATION
Classic
omitted
omitted
included
included
omitted
included
Database
Mixed
Metadata Version
The relational interface supports two versions of metadata, referred
to as version 1 (V1) and version 2 (V2). Metadata version applies to
all data dictionary files (DDFs) within that database. V1 metadata is
the default.
Among other features, V2 metadata allows for many identifier names
to be up to 128 bytes long and for permissions on views and stored
procedures. See Versions of Metadata on page 2-2 for a complete
discussion.
You may include or omit the V1_METADATA keyword to specify V1
metadata. You must include the V2_METADATA keyword to specify
V2 metatadata.
See also Versions of Metadata on page 2-2.
Examples
3-49
See Also
3-50
Grammar Statements
CREATE FUNCTION
The CREATE FUNCTION statement creates a scalar user-defined
function (UDF) in the database. You can invoke the user-defined
functions from a query.
Syntax
RETURN scalar_expression
END;
Arguments
function_name
Name of the scalar UDF. UDF names must conform to the rules for
identifiers and must be unique within the database and to its owner.
parameter_name
The return value of a scalar UDF. Only scalar types are supported.
body_of_function
3-51
Restrictions
Limits
Limit
Number of parameters
300
64 KB
128 characters
The following are the supported data types for input scalar
parameters and returned values in Pervasive PSQL.
Table 3-1 Supported Input Parameters and Returned Data Types
3-52
BIGINT
BINARY
BIT
BLOB
CHAR
CHARACTER
CLOB
CURRENCY
DATE
DEC
DECIMAL
DECIMAL
DOUBLE
DOUBLE PRECISION
FLOAT
IDENTITY
INT
INTEGER
LONG
LONG VARBINARY
LONG VARCHAR
LONGVARBINARY
LONGVARCHAR
NUMERIC
NUMERIC
NUMERIC
REAL
SMALLIDENTITY
SMALLINT
SMALLINT
Grammar Statements
Table 3-1 Supported Input Parameters and Returned Data Types continued
SMALLINT
SPT_BINARY
SPT_BIT
SPT_CHAR
SPT_DATE
SPT_DECIMAL
SPT_DOUBLE
SPT_INTEGER
SPT_LONGVARBIN
SPT_LONGVARCHAR
SPT_NUMERIC
SPT_REAL
SPT_SMALLINT
SPT_TIME
SPT_TIMESTAMP
SPT_TINYINT
SPT_VARBINARY
SPT_VARCHAR
TIME
TIMESTAMP
TIMESTAMP
TINYINT
UBIGINT
UINT
UINTEGER
UNIQUEIDENTIFIER
USMALLINT
UTINYINT
VARBINARY
VARBINARY
VARCHAR
Examples
3-53
3-54
Grammar Statements
UDF in Procedures
CREATE PROCEDURE procTestUdfInvoke() AS
begin
DECLARE :a integer;
SET :a = 99 + (222 + Demodata.GetSmallest(10, 9)) +
10;
PRINT :a;
end;
CALL procTestUdfInvoke()
The following example is similar to the previous one, except that the
database qualifier is omitted.
create procedure procTestUdfInvoke2() as
begin
declare :a integer;
set :a = 99 + (222 + GetSmallest(10, 9)) +10;
print :a;
end;
call procTestUdfInvoke2
3-55
Recursive UDF
CREATE FUNCTION factorial(IN :n integer) RETURNS double
AS BEGIN
DECLARE :fact double;
IF (:n <= 0) THEN
SET :fact = 1;
else
SET :fact = (:n * Demodata.factorial(:n - 1));
END IF;
RETURN :fact;
END;
3-56
Grammar Statements
IUDF as an expression
SELECT 10 + Demodata.Getsmallest(10,20) + 15
See Also
3-57
CREATE GROUP
The CREATE GROUP statement creates one or more security
groups.
Syntax
Remarks
::= user-defined-name
Examples
See Also
3-58
Grammar Statements
CREATE INDEX
Use the CREATE INDEX statement to create a named index for a
specified table.
Syntax
CREATE [ UNIQUE | PARTIAL ] [ NOT MODIFIABLE ] INDEX indexname [ IN DICTIONARY ] ON table-name [ index-definition ]
index-name
::= user-defined-name
table-name
::= user-defined-name
index-definition
]... )
index-segment-definition
Remarks
3-59
Index Segments
The number of index segments that you may use depends on the
files page size.
Page Size (bytes)
512
9.0
9.5
rounded up2
1,024
23
23
97
1,536
24
24
rounded up2
2,048
54
54
97
2,560
54
54
rounded up2
3,072
54
54
rounded up2
3,584
54
54
rounded up2
4,096
119
119
1193
8,192
n/a1
119
1193
16,384
n/a1
n/a1
1193
2rounded
3The
3-60
Grammar Statements
See also status code 6008: Too Many Segments on page 1-139 in
Status Codes and Messages.
PARTIAL
3-61
Partial indexes may only be added to columns with the data type
of CHAR or VARCHAR.
Partial index columns should always be the last column in the
index definition, or should be the only column in the index
definition.
When the the partial index column is the only column in the
index, the column size can be up to 8000 bytes, but the user-data
index segment will be of size 255 bytes minus any overhead
segments.
WHERE col
LIKE 'literal%'
'literal'
WHERE col
WHERE col
LIKE ?
TABLE such that the new length fits in 255 bytes of the index or
when the new length overshoots 255 bytes, it is the responsibility
of the user to drop the index and recreate it according to his/her
requirements.
Examples
3-62
Grammar Statements
Next, the example creates a partial index named idx_01 using the
Description column.
CREATE PARTIAL INDEX idx_01 on part_tbl (description);
The following example creates a partial index named idx_02 for the
same table in the previous example. Instead, this example uses the
PartId, SerialNo, and Description columns collectively for the index.
CREATE PARTIAL INDEX idx_02 on part_tbl (partid,
serialno, description);
The following table details the index columns so that you may
understand how the wide column is allocated in the index.
Column Name
Data Type
Size
PartID
Integer
SerialNo
Varchar
200
Description
Char
300
Overhead
Size in Index
4
201
50
255
IN DICTIONARY
3-63
3-64
Grammar Statements
See Also
3-65
CREATE PROCEDURE
The CREATE PROCEDURE statement creates a new stored
procedure. Stored procedures are SQL statements that are predefined and saved in the database dictionary.
Syntax
::= user-defined-name
proc-expr
result
as-or-semicolon
proc-stmt
stmt
::= AS | ;
3-66
Grammar Statements
| delete-statement
| FETCH [ fetch-orientation [ FROM ] ]cursor-name [ INTO variablename
[ , variable-name ] ]
::= commit-statement
| rollback-statement
3-67
| release-statement
commit-statement
rollback-statement
release-statement
create-table-statement ::=
alter-table-statement ::=
drop-table-statement ::=
create-index-statement ::=
drop-index-statement ::=
create-view-statement ::=
drop-view-statement ::=
grant-statement ::=
revoke-statement ::=
set-statement ::=
label-name
cursor-name
::= user-defined-name
::= user-defined-name
variable-name
::= user-defined-name
proc-search-condition
fetch-orientation
sqlstate-value
Remarks
::= | NEXT
::= 'string'
3-68
Grammar Statements
3-69
Caching Exclusions
Data Type
Restrictions
Limits
Examples
BFLOAT4
BFLOAT8
MONEY
NUMERIC
NUMERICSA
NUMERICSTS
Limit
300
300
64 KB
3-70
Grammar Statements
BEGIN
INSERT INTO Enrolls VALUES(:Stud_id, :Class_id,
:GPA);
END;
The following procedure reads the Class table, using the classId
parameter passed in by the caller and validates that the course
enrollment is not already at its limit.
CREATE PROCEDURE Checkmax(in :classid integer);
Begin
DECLARE :numenrolled integer;
DECLARE :maxenrolled integer;
SELECT COUNT(*) INTO :numenrolled FROM Enrolls WHERE
class_ID = :classid;
SELECT Max_size INTO :maxenrolled FROM Class WHERE id
= :classid;
IF (:numenrolled > :maxenrolled) THEN
PRINT Enrollment Failed. Number of students
enrolled reached maximum allowed for this
class ;
ELSE
PRINT Enrollment Possible. Number of students
enrolled has not reached maximum allowed for
this class;
END IF;
END;
CALL Checkmax(101)
3-71
You cannot call the above procedure using a literal value (as in call
prociodate(1982-03-03)), because it requires an output
parameter. You must first bind the parameter using ODBC calls, or
you can test the procedure by creating another procedure to call it, as
shown here:
CREATE PROCEDURE pdate();
BEGIN
DECLARE :a DATE;
CALL prociodate(:a);
PRINT :a;
END
CALL pdate
3-72
Grammar Statements
The following procedure returns data from the Class table where the
Start Date is equal to the date passed in on the CALL statement.
CREATE PROCEDURE DateReturnProc (IN :pdate date, IN
:flag) AS
BEGIN
IF (:flag = 1) THEN
SELECT ID, Name, Room_Number FROM Class
WHERE start_date = :pdate;
3-73
3-74
Grammar Statements
SET :i = :i + 1;
END;
END WHILE;
END
CALL varsub1
SELECT * FROM table1
-- returns 110 rows
3-75
This example uses a stored procedure to create two tables and insert
one row of default values into each. It then turns on security and
grants permissions to user user1.
CREATE PROCEDURE p1 ();
BEGIN
CREATE TABLE t1 (c1 INT DEFAULT 10, c2 INT DEFAULT
100);
CREATE TABLE t2 (c1 INT DEFAULT 1 , c2 INT DEFAULT 2);
INSERT INTO t1 DEFAULT VALUES;
INSERT INTO t2 DEFAULT VALUES;
SET SECURITY = larry;
END;
CALL p1
SELECT * FROM t1
-- returns 10, 100
SELECT * FROM t2
-- returns 1, 2
SELECT * FROM t2
-- returns an error, table not found
3-76
Grammar Statements
3-77
Using Stored
Procedures
General Stored
Procedure Engine
Limitations
3-78
Grammar Statements
Limits to SQL
Variables and
Parameters
Limits to Cursors
3-79
CREATE TABLE
The CREATE TABLE statement creates a new table in a database.
CREATE TABLE contains functionality that goes beyond minimal or
core SQL conformance. CREATE TABLE supports Referential
Integrity features. Pervasive PSQL conforms closely to SQL 92 with
the exception of ColIDList support.
You can also create temporary tables with the CREATE TABLE
statement. See CREATE (temporary) TABLE on page 3-93.
Syntax
integer
integer
| default-value-expression - default-value-expression
| default-value-expression * default-value-expression
| default-value-expression / default-value-expression
| default-value-expression & default-value-expression
| default-value-expression | default-value-expression
| default-value-expression ^ default-value-expression
| ( default-value-expression )
3-80
Grammar Statements
| -default-value-expression
| +default-value-expression
| ~default-value-expression
| ?
| literal
| scalar-function
| { fn scalar-function }
| USER
| NULL
literal ::= 'string'
| number
| { d 'date-literal' }
| { t 'time-literal' }
| { ts 'timestamp-literal' }
scalar-function ::= see Scalar Functions on page 5-1
column-constraint ::= [ CONSTRAINT constraint-name ] col-constraint
constraint-name ::= user-defined-name
col-constraint ::= NOT NULL
| UNIQUE
| PRIMARY KEY
| REFERENCES table-name [ ( column-name ) ] [ referential-actions ]
table-constraint-definition ::= [ CONSTRAINT constraint-name ] table-constraint
table-constraint ::=
| referential-delete-action [ referential-update-action ]
referential-update-action ::= ON UPDATE RESTRICT
referential-delete-action ::= ON DELETE CASCADE
| ON DELETE RESTRICT
3-81
Remarks
The total size of the fixed-length portion of any data record may not
exceed 65535 bytes. The fixed-length portion of any data record is
made up of the following:
3-82
all the columns that have a fixed sized (all columns except for
LONGVARCHAR and LONGVARBINARY)
Grammar Statements
Nullable?
VARCHAR(216)
Yes
VARCHAR(213)
All columns
CHAR(42)
1494
All columns
Each VARCHAR has two extra bytes reserved for it. One bite for the
preceding NULL indicator and one trailing byte because VARCHAR
is implemented as a ZSTRING. Each CHAR has a preceding byte
reserved for the NULL indicator.
Therefore, the record size is 1 x 218 + 5 x 215 + 1494 x 43 = 65535
bytes
In this example, you could not add another column of any length
without exceeding the fixed-length limit.
Delete Rule
3-83
which a foreign key value refers. The delete rules you can choose are
as follows:
If you do not specify a delete rule, Pervasive PSQL applies the restrict
rule by default.
Use caution with delete cascade. Pervasive PSQL allows a circular
delete cascade on a table that references itself. See examples in
Delete Cascade on page 6-5 in Advanced Operations Guide.
Update Rule
Pervasive PSQL enforces the update restrict rule. This rule prevents
the addition of a row containing a foreign key value if the parent
table does not contain the corresponding primary key value. This
rule is enforced whether or not you use the optional ON UPDATE
clause, which allows you to specify the update rule explicitly.
IN DICTIONARY
3-84
Grammar Statements
3-85
3-86
Grammar Statements
The DCOMPRESS option specifies that the data file for the specified
table should use record compression to reduce the file size on disk.
The following example creates a table with record compression and
page size 1024 bytes:
CREATE TABLE t1 DCOMPRESS PAGESIZE=1024 (c1 INT DEFAULT
10, c2 CHAR(10) DEFAULT 'abc')
PCOMPRESS
The PCOMPRESS option specifies that the data file for the specified
table should use page compression. The following example creates a
table with page compression and page size 1024 bytes:
CREATE TABLE t1 PCOMPRESS PAGESIZE=1024 (c1 INT DEFAULT
10, c2 CHAR(10) DEFAULT 'abc')
PAGESIZE
The PAGESIZE option specifies that the data file for the specified
table should use pages of size bytes. The value of size can be any of the
following depending on file version:
3-87
512 4096 for file versions prior to 9.0 (a multiple of 512 bytes
up to 4096).
512, 1024, 1536, 2048, 2560, 3072, 3584, 4096, or 8192 for file
version 9.0.
1024, 2048, 4096, 8192, or 16384 for file versions 9.5 and newer.
The following example creates a table with file compression and page
size 8192 bytes, specifying creation of the particular data file
identified by the relative path, ..\data1.mkd:
CREATE TABLE t1 DCOMPRESS PAGESIZE=8192
USING ..\data1.mkd (c1 INT DEFAULT 10, c2 CHAR(10)
DEFAULT 'abc')
LINKDUP
Multiple records may carry the same duplicated value for index keys.
The two methods to keep track of the records with duplicate key
values are called linked duplicates (linkdup) and repeating
duplicates. (For a detailed discussion of both methods, see Methods
for Handling Duplicate Keys on page 13-14 in Advanced Operations
Guide.)
The following conditions apply to the use of the LINKDUP keyword.
3-88
a CREATE INDEX statement cannot create a repeatingduplicate key if pointers are still reserved for linkedduplicate keys.
The ALTER TABLE statement does not support the LINKDUP
option.
Grammar Statements
Examples
UBIGINT,
Dept_Name
CHAR(20) CASE,
Designation
CHAR(10) CASE,
Salary
CURRENCY,
Building_Name
CHAR(25) CASE,
Room_Number
UINTEGER,
Rsch_Grant_Amount
PRIMARY KEY (ID))
DOUBLE,
The following example is similar to the one just discussed, except the
ID column, which is the primary key, is designated as UNIQUE.
CREATE TABLE organizations
(ID UBIGINT UNIQUE,
Name LONGVARCHAR,
Advisor CHAR(30),
Number_of_people INTEGER,
Date_started DATE,
Time_started TIME,
Date_modified TIMESTAMP,
Total_funds DOUBLE,
3-89
3-90
Grammar Statements
parent row before you can have foreign keys referring to that row.
This is the default behavior of Pervasive PSQL. Moreover, Pervasive
PSQL does not support any other UPDATE rules. Thus, whether this
rule is stated explicitly or not makes no difference.
CREATE TABLE StudentAddress (id UBIGINT REFERENCES
Student (id) ON UPDATE RESTRICT, addr CHAR(128))
Upper.alt treats upper and lower case letters the same for sorting. For
example, if a database has values abc, ABC, DEF, and Def, inserted in
that ordered, the sorting with upper.alt returns as abc, ABC, DEF,
and Def. (The values abc and ABC, and the values DEF and Def are
considered duplicates and are returned in the order in which they
were inserted.) Normal ASCII sorting sequences upper case letters
before lower case, such that the sorting would return as ABC, DEF,
Def, abc.
The following example creates a table, t1, and reserves the number of
pointers to use for linked duplicate keys to four. The CREATE
INDEX statements create index keys for the table.
DROP table t1
CREATE table t1 LINKDUP=4 (c1 int, c2 int, c3 int)
CREATE
CREATE
CREATE
CREATE
CREATE
INDEX link_1
INDEX link_2
UNIQUE INDEX
INDEX link_4
INDEX link_5
on t1(c1,c2)
on t1(c1,c3)
link_3 on t1(c3)
on t1(c1)
on t1(c2)
3-91
See Also
3-92
Grammar Statements
integer
integer
| default-value-expression - default-value-expression
| default-value-expression * default-value-expression
| default-value-expression / default-value-expression
| default-value-expression & default-value-expression
| default-value-expression | default-value-expression
| default-value-expression ^ default-value-expression
| ( default-value-expression )
| -default-value-expression
| +default-value-expression
| ~default-value-expression
| ?
| literal
| scalar-function
| { fn scalar-function }
| USER
| NULL
3-93
| number
| { d 'date-literal' }
| { t 'time-literal' }
| { ts 'timestamp-literal' }
scalar-function ::=
| UNIQUE
| PRIMARY KEY
| REFERENCES table-name [ ( column-name ) ] [ referential-actions ]
table-constraint-definition ::= [ CONSTRAINT constraint-name ] table-constraint
table-constraint ::=
| referential-delete-action [ referential-update-action ]
referential-update-action ::= ON UPDATE RESTRICT
referential-delete-action ::= ON DELETE CASCADE
| ON DELETE RESTRICT
collation-name ::= 'string' | user-defined-name
Remarks
3-94
Grammar Statements
Local
Global
Global Temporary
Table
Outside
of SP1
Within SP
Outside
of SP
Within SP
yes
yes
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
no
no
yes3
yes4
yes3
yes4
yes3
yes4
yes3
yes4
no
no
yes
yes
3-95
Global Temporary
Table
Outside
of SP1
Within SP
Outside
of SP
Within SP
yes
yes
yes
yes
yes
yes
yes
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
yes
yes
yes
yes
yes
yes
yes
no
no
yes
yes
not
applicable
no
not
applicabl
e
yes
not
applicable
no
not
applicabl
e
no
not
applicable
yes7
not
applicabl
e
yes9
yes
yes
yes
yes
yes
yes8
yes
yes
not
applicable
yes
not
applicabl
e
no
3-96
Grammar Statements
Global Temporary
Table
Outside
of SP1
Within SP
Outside
of SP
Within SP
not
applicable
not
applicable
yes
yes
2The
database engine automatically appends the name of the stored procedure and a session-specific ID to
the user-defined name to ensure a unique table name. This functionality is transparent to the user.
3The
total length of the table name includes # or ##, plus an underscore, plus a session ID. The session ID
can be 8, 9, or 10 bytes depending on the operating system. See Identifier Restrictions by Identifier Type in
Advanced Operations Guide.
4The
total length of the table name includes # or ##. plus an underscore, plus the name of the stored
procedure, plus an underscore, plus a session ID. The session ID can be 8, 9, or 10 bytes depending on the
operating system. See Identifier Restrictions by Identifier Type in Advanced Operations Guide.
5Constraint
6A
7
table can be created and populated with data with a single SELECT INTO statement.
The table name already exists from the first execution of the stored procedure.
8If
3-97
3-98
Grammar Statements
3-99
UBIGINT,
Dept_Name
CHAR(20) CASE,
Building_Name
CHAR(25) CASE,
Room_Number
UINTEGER,
3-100
Grammar Statements
PRINT :val1_int;
PRINT :val2_char;
COMMIT;
END;
CALL P11 ()
3-101
See Also
3-102
Grammar Statements
CREATE TRIGGER
The CREATE TRIGGER statement creates a new trigger in a
database. Triggers are a type of stored procedure that are
automatically executed when data in a table is modified with an
INSERT, UPDATE, or DELETE.
Unlike a regular stored procedure, a trigger cannot be executed
directly nor can it have parameters. Triggers do not return a result set
nor can they be defined on views.
Syntax
Remarks
(:).
OLD (OLD correlation-name) and NEW (NEW correlation-name) can be
used inside triggers, not in a regular stored procedure.
In a DELETE or UPDATE trigger, OLD or a OLD correlation-name
must be prepended to a column name to reference a column in the
row of data prior to the update or delete operation.
3-103
Examples
The following example creates a trigger that records any new values
inserted into the Tuition table into TuitionIDTable.
CREATE TABLE Tuitionidtable (PRIMARY KEY(id), id
UBIGINT)
CREATE TRIGGER InsTrig
BEFORE INSERT ON Tuition
REFERENCING NEW AS Indata
FOR EACH ROW
INSERT INTO Tuitionidtable VALUES(Indata.ID);
3-104
Grammar Statements
AFTER UPDATE ON A FOR EACH ROW
UPDATE B SET col1 = NEW.col1, col2 = NEW.col2 WHERE
B.col1 = OLD.col1 AND B.col2 = OLD.col2;
Note that OLD and NEW in the example keep the tables
synchronized only if table A is altered with non-positional SQL
statements. If the ODBC SQLSetPos API or a positioned update or
delete is used, then the tables stay synchronized only if table A does
not contain any duplicate records. An SQL statement cannot be
constructed to alter one record but leave another duplicate record
unaltered.
See Also
3-105
CREATE USER
The CREATE USER statement creates a new user account in a
database.
This function can be used to create a user account in a database with
a password, without a password, or as member of a group.
Syntax
Remarks
3-106
Grammar Statements
CREATE USER pgranger
The new user name is pgranger. The users password is NULL and the
user account is not a member of any group.
CREATE USER polly granger
The following examples show how to create a new user account with
login privileges that is not a member of any group.
CREATE USER pgranger WITH PASSWORD Prvsve1
The new user name is pgranger. The users password is Prsve1 (casesensitive).
CREATE USER pgranger WITH PASSWORD Nonalfa$
The new user name is pgranger. The new user account is a assigned
to the group developers.
The new user name is pgranger. The new user account is assigned to
the group developers and has the case-sensitive password Prvsve1.
The order of this syntax (CREATE USER..WITH PASSWORD...IN
GROUP) is absolutely necessary.
See Also
3-107
CREATE VIEW
The CREATE VIEW statement defines a stored view, or virtual table.
Syntax
202)
Remarks
DISTINCT
GROUP BY
ORDER BY
Scalar Functions
Scalar subquery
TOP
UNION
3-108
Grammar Statements
ORDER BY
In a subsequent query on the view, you may use the column headings
in your SELECT statement:
SELECT lastn, firstn FROM vw_Person
The user executing the view must have SELECT permissions on the
Person table.
3-109
In a subsequent query on the view, you may use the column headings
in your SELECT statement, as shown in the next example.
SELECT lastn, firstn FROM vw_Person
The view returns the following (for brevity, not all records are
shown).
Last_Name
=========
Vqyles
Qulizada
Ragadio
Luckey
Sokell
Gyduska
Happy
Nix
3-110
First_Name
==========
Rex
Ahmad
Ernest
Anthony
Chester
Michael
Anthony
Anna
Phone
==========
2105551871
2105552233
2105554654
2105557628
2105559149
5125550001
5125550004
5125550006
Grammar Statements
The following example creates a view that returns the grade point
average (GPA) of students in descending order, and, for each GPA
ordering, lists the students by last name descending.
CREATE VIEW vw_gpa AS SELECT Last_Name,Left(First_
Name,1) AS First_Initial,Cumulative_GPA AS GPA FROM
Person LEFT OUTER JOIN Student ON Person.ID=Student.ID
ORDER BY Cumulative_GPA DESC, Last_Name
The view returns the following (for brevity, not all records are
shown).
Last_Name
=========================
Abuali
Adachi
Badia
Rowan
Ujazdowski
Wotanowski
Gnat
Titus
Mugaas
Pabalan
First_Initial
===============
I
K
S
A
T
H
M
A
M
R
GPA
======
4.000
4.000
4.000
4.000
4.000
4.000
3.998
3.998
3.995
3.995
The following example creates a view that returns the top 10 records
from the Person table, ordered by ID.
CREATE VIEW vw_top10 AS SELECT TOP 10 * FROM person ORDER
BY id;
The view returns the following (for brevity, not all columns are
shown).
ID
=========
100062607
100285859
100371731
100592056
100647633
100822381
101042707
101135758
101369010
101581226
First_Name
==========
Janis
Lisa
Robert
Andrew
Robert
Roosevelt
Avram
Ismail
Bruno
Robert
Last_Name
==========
Nipart
Tumbleson
Mazza
Sugar
Reagen
Bora
Japadjief
Badad
Ippolite
Obici
3-111
The view returns the following (for brevity, not all records are
shown).
First_Name
===========
Zyrowski
Zynda
Zydanowicz
Yzaguirre
Yyounce
Xystros
Xyois
Xu
Wyont
Wynalda
Wykes
See Also
3-112
Grammar Statements
DECLARE
Remarks
Examples
See Also
3-113
DECLARE CURSOR
The DECLARE CURSOR statement defines an SQL cursor.
Syntax
Remarks
Examples
The following example creates a cursor that selects values from the
Degree, Residency, and Cost_Per_Credit columns in the Tuition
table and orders them by ID number.
DECLARE BTUCursor CURSOR
FOR SELECT Degree, Residency, Cost_Per_Credit
FROM Tuition
ORDER BY ID;
3-114
Grammar Statements
See Also
3-115
DEFAULT
You may use the DEFAULT keyword in the following contexts:
3-116
Grammar Statements
Remarks
BFLOAT4, BFLOAT8
SQL_BIGINT
BIGINT, UBIGINT
SQL_BIT
BIT
SQL_CHAR
CURRENCY
SQL_DECIMAL
DECIMAL
SQL_DOUBLE
DOUBLE
SQL_FLOAT
IDENTITY1
SQL_INTEGER
INTEGER, UINTEGER
SQL_LONGVARCHAR
NUMERIC
SQL_NUMERIC
NUMERICSA
SQL_REAL
NUMERICSTS
SQL_SMALLINT
REAL
SQL_TINYINT
SMALLIDENTITY1
SQL_VARCHAR
SMALLINT, USMALLINT
TINYINT, UTINYINT
BINARY
SQL_BIGINT
LONGVARBINARY
SQL_BINARY
SQL_BIT
SQL_CHAR
SQL_GUID
SQL_INTEGER
SQL_LONGVARBINARY
SQL_LONGVARCHAR
SQL_SMALLINT
SQL_TINYINT
SQL_VARCHAR
3-117
CHAR
SQL_BIGINT
LONGVARCHAR
SQL_BIT
VARCHAR
SQL_CHAR
SQL_DATE
SQL_DECIMAL
SQL_DOUBLE
SQL_FLOAT
SQL_GUID
SQL_INTEGER
SQL_LONGVARCHAR
SQL_NUMERIC
SQL_REAL
SQL_SMALLINT
SQL_TIME
SQL_TIMESTAMP
SQL_TINYINT
SQL_VARCHAR
SQL_CHAR
SQL_LONGVARCHAR
SQL_VARCHAR
SQL_GUID
SQL_CHAR
SQL_DATE
SQL_LONGVARCHAR
SQL_TIMESTAMP
SQL_VARCHAR
UNIQUEIDENTIFIER
DATE
3-118
Grammar Statements
TIME
SQL_CHAR
SQL_LONGVARCHAR
SQL_TIME
SQL_TIMESTAMP
SQL_VARCHAR
SQL_CHAR
SQL_DATE
SQL_LONGVARCHAR
SQL_TIMESTAMP
SQL_VARCHAR
Examples
3-119
3-120
Grammar Statements
(
col SMALLINT DEFAULT 3 * -20000
)
INSERT INTO Tab values(DEFAULT)
Expressions as
Default Values for
Date or Time
Columns
Defaults specify the values that are used in a column if you do not
specify a value for the column when inserting a row.
To assign an expression as a default on a column, define a default
value using the DEFAULT keyword in the CREATE TABLE
statement. For more details on creating a table, see CREATE
TABLE on page 3-80.
In addition to literals and NULL values, Pervasive PSQL also allows
you to specify date and time scalar functions and expressions as
default values for columns of the appropriate data types.
CURRENT_USER() is allowed as a default value for string columns
CHAR and VARCHAR.
3-121
The following table lists the specific date and time scalar functions
that you can invoke to provide the default value for a column of the
appropriate data type:
Table 3-5 Date and Time Scalar Functions as Default Values
Function
Default for
CURRENT_DATE( )
CURDATE( )
CURRENT_TIME( )
CURTIME( )
CURRENT_TIMESTAMP( )
NOW( )
When you specify a scalar function as the default value for a column
in INSERT and UPDATE statements, Pervasive PSQL invokes the
specified scalar function to set the value of such a column to the
result of the function call.
See Also
3-122
Grammar Statements
DELETE (positioned)
Use the positioned DELETE statement to remove the current row of
a view associated with an SQL cursor.
Syntax
Remarks
Examples
3-123
See Also
3-124
Grammar Statements
DELETE
This statement deletes specified rows from a database table or view.
Syntax
| [db-name.]table-name [ [ AS ] alias-name ]
| [db-name.]view-name [ [ AS ] alias-name ]
| join-definition
| ( join-definition )
| ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name
]... ) ]
outer-join-definition ::= table-reference outer-join-type JOIN table-reference ON searchcondition
outer-join-type ::= LEFT [ OUTER ] | RIGHT [ OUTER ] | FULL [
OUTER ]
search-condition ::= search-condition AND search-condition
| search-condition OR search-condition
| NOT search-condition
| ( search-condition )
| predicate
db-name ::= user-defined-name
view-name ::= user-defined-name
join-definition ::= table-reference [ join-type ] JOIN table-reference ON searchcondition
3-125
[ OUTER ]
table-subquery ::= query-specification [ [ UNION [ ALL ]
query-specification ]... ]
Remarks
3-126
Grammar Statements
[Pervasive][ODBC Client Interface][LNA][Pervasive]
[ODBC Engine Interface]Table alias not allowed in
UPDATE/DELETE statement with optional FROM.
Examples
The following statement deletes the row for first name Ellen from the
person table in the sample database.
DELETE FROM person WHERE First_Name = 'Ellen'
3-127
DISTINCT
Remarks
Examples
See Also
3-128
Grammar Statements
DROP DATABASE
The DROP DATABASE statement deletes a database. Only the
Master user can issue the statement.
Syntax
Remarks
3-129
See Also
3-130
Grammar Statements
DROP FUNCTION
The DROP FUNCTION statement removes an existing user-defined
function (UDF) from the database.
Note An error message appears if you attempt to delete a UDF
Syntax
Examples
See Also
3-131
DROP GROUP
This statement removes one or more groups in a secured database.
Syntax
Remarks
Only the Master user can perform this statement. Separate multiple
group names with a comma. A group must be empty to be dropped.
Security must be turned on to perform this statement.
Examples
See Also
3-132
Grammar Statements
DROP INDEX
This statement drops a specific index from a designated table.
Syntax
Remarks
The following statement drops the named index from the Faculty
table.
DROP INDEX Faculty.Dept
3-133
See Also
3-134
Grammar Statements
DROP PROCEDURE
This statement removes one or more stored procedures from the
current database.
Syntax
Examples
See Also
3-135
DROP TABLE
This statement removes a table from a designated database.
Syntax
IN DICTIONARY
Examples
The following statement drops the class table definition from the
dictionary.
DROP TABLE Class
See Also
3-136
Grammar Statements
DROP TRIGGER
This statement removes a trigger from the current database.
Syntax
Examples
See Also
3-137
DROP USER
The DROP USER statement removes an existing user account(s)
from a database.
Syntax
Remarks
Examples
See Also
3-138
Grammar Statements
DROP VIEW
This statement removes a specified view from the database.
Syntax
Remarks
Examples
See Also
3-139
END
Remarks
3-140
Grammar Statements
EXECUTE
The EXECUTE statement has two uses:
Syntax
procedure-parameter
procedure
Within a user-defined stored procedure:
EXEC[UTE] ( string [ + string ]... )
string ::=
string
Examples
3-141
See Also
3-142
Grammar Statements
EXISTS
The EXISTS keyword tests whether rows exist in the result of a
subquery. True is returned if the subquery contains any rows.
Syntax
EXISTS ( subquery )
Remarks
For every row the outer query evaluates, Pervasive PSQL tests for the
existence of a related row from the subquery. Pervasive PSQL
includes in the statement's result table each row from the outer query
that corresponds to a related row from the subquery.
You may use EXISTS for a subquery within a stored procedure.
However, the subquery SELECT statement within the stored
procedure may not contain a COMPUTE clause or the INTO
keyword.
In most cases, a subquery with EXISTS can be rewritten to use IN.
Pervasive PSQL can process the query more efficiently if the query
uses IN.
Examples
3-143
The following procedure selects the ID from the Person table using a
value as an input parameter. The first EXEC of the procedure returns
Exists returned true. The second EXEC returns Exists returned
false.
CREATE PROCEDURE ex1(IN :vID INTEGER) AS
BEGIN
IF EXISTS ('SELECT id FROM person WHERE id < :vID)
THEN PRINT 'Exists returned true';
ELSE PRINT 'Exists returned false';
ENDIF;
END;
EXEC ex1(222222222)
EXEC ex1(1)
See Also
3-144
Grammar Statements
FETCH
Remarks
you will not be able to control the flow of the cursor records even
by omitting NEXT FROM.
Syntax
Examples
3-145
See Also
3-146
Grammar Statements
FOREIGN KEY
Remarks
name before you can add a foreign key or conduct any other
referential integrity (RI) operation. Also, when security is
enabled, you must have the Reference right on the table to which
the foreign key refers before you can add the key.
Include a FOREIGN KEY clause in your CREATE TABLE statement
to define a foreign key on a dependent table. In addition to specifying
a list of columns for the key, you can define a name for the key.
The columns in the foreign key column may be nullable. However,
ensure that pseudo-null columns do not exist in an index that does
not index pseudo-null values.
The foreign key name must be unique in the dictionary. If you omit
the foreign key name, Pervasive PSQL uses the name of the first
column in the key as the foreign key name. This can cause a duplicate
foreign key name error if your dictionary already contains a foreign
key with that name.
When you specify a foreign key, Pervasive PSQL creates an index on
the columns that make up the key. This index has the same attributes
as the index on the corresponding primary key except that it allows
duplicate values. To assign other attributes to the index, create it
explicitly using a CREATE INDEX statement. Then, define the
foreign key with an ALTER TABLE statement. When you create the
index, ensure that it does not allow null values and that its case and
collating sequence attributes match those of the index on the
corresponding primary key column.
The columns in a foreign key must be the same data types and
lengths and in the same order as the referenced columns in the
primary key. The only exception is that you can use an integer
column in the foreign key to refer to an IDENTITY or
SMALLIDENTITY column in the primary key. In this case, the two
columns must be the same length.
3-147
The following statement adds a new foreign key to the Class table.
(The Faculty column is defined as an index that does not include null
values.)
ALTER TABLE Class ADD CONSTRAINT Teacher FOREIGN KEY
(Faculty_ID)
REFERENCES Faculty ON DELETE RESTRICT
3-148
Grammar Statements
GRANT
The GRANT statement creates new user IDs and gives permissions
to specific users in a secured database.
Syntax
|
|
|
|
|
|
|
ALL
3-149
Remarks
CREATE TABLE
CREATETAB
CREATE VIEW
CREATEVIEW
CREATE PROCEDURE
CREATESP
LOGIN TO
GRANT LOGIN TO creates a user and allows that user to access the
secured database. You must specify a user name and user password
to create a user. Optionally, you may specify the group to which you
want the user to belong. The group must already exist. You cannot
create a group with the GRANT LOGIN statement.
Constraints
The following constraints apply to permissions:
3-150
By Object Type
ALL Key Word
Grammar Statements
By Object Type
Table 3-6 Permissions Applicable To Object Type
Permission
CREATETAB
Table1
View1
CREATEVIEW
CREATESP
ALTER2
DELETE
INSERT
REFERENCES
SELECT
UPDATE
EXECUTE3
Stored Procedure
1Columns
3-151
Table
View
ALTER1
DELETE
INSERT
REFERENCES
SELECT
UPDATE
Stored Procedure
EXECUTE
To drop a table, view, or stored procedure, a user must have ALTER permission
on that object. Trused views and stored procedures can be dropped only by the
Master user.
3-152
Grammar Statements
Note If you wish to use groups, you must set up the groups
3-153
3-154
Grammar Statements
Characteristic
Notes
Trusted view or
trusted stored
procedure
Requires V2 metadata
3-155
Table 3-8 Characteristics of Trusted and Non-trusted Views and Stored Procedures continued
Object
Characteristic
Notes
Non-trusted view or
non-trusted stored
procedures
Examples
3-156
Grammar Statements
Note If the a user account that is granted login rights using the
3-157
If there are spaces in a name you may use double quotes as in the
following example. This statement grants login rights to user named
Jerry Gentry and Punita and specifies their password as sun and
moon respectively
GRANT LOGIN TO "Jerry Gentry":sun, Punita:moon
The following example grants the login rights to a user named Jerry
Gentry with password 123456 and a user named travisk with
password abcdef. It also adds them to the group pervasive_dev
GRANT LOGIN TO "Jerry Gentry":123456, travisk:abcdef IN
GROUP pervasive_dev
The Master user has all rights on a table that does not have an owner
name. You can set an owner name on a table with the Maintenance
utility. The Btrieve owner name is case sensitive.
After the Master user performs the following set of SQL statements,
the user "jsmith" has SELECT access to all tables in the current
database. The user also has DELETE access to tab1 and UPDATE
access to tab2.
GRANT DELETE ON tab1 TO jsmith
GRANT SELECT ON * TO jsmith
GRANT UPDATE ON tab2 TO jsmith
3-158
Grammar Statements
3-159
GROUP BY
Remarks
Examples
This same example could use an alias, in this case dn, to produce
the same result:
SELECT Dept_Name dn FROM Course GROUP BY dn
The rows operated on by the set function are those rows remaining
after the WHERE search condition is applied. In this example, only
those rows in the faculty table that have Salary > 80000 are counted:
SELECT COUNT(*) FROM Faculty WHERE Salary > 80000 GROUP
BY Dept_Name
3-160
Grammar Statements
See Also
3-161
HAVING
Remarks
Examples
This same example could use aliases, in this case dn and ct, to
produce the same result:
SELECT Dept_Name dn, COUNT(*) ct FROM Course GROUP BY dn
HAVING ct > 5
See Also
3-162
Grammar Statements
IF
Remarks
Syntax
IF ( Boolean_condition )
BEGIN
Sql-statements
END
ELSE
BEGIN
Sql-statements
END
3-163
Examples
The following example uses the IF statement to test the loop for a
defined condition (SQLSTATE = '02000'). If it meets this condition,
then the WHILE loop is terminated.
FETCH_LOOP:
WHILE (:counter < :NumRooms) DO
FETCH NEXT FROM cRooms INTO :CurrentCapacity;
IF (SQLSTATE = '02000') THEN
LEAVE FETCH_LOOP;
END IF;
SET :counter = :counter + 1;
SET :TotalCapacity = :TotalCapacity +
:CurrentCapacity;
END WHILE;
IF(:vInteger >50)
BEGIN
set :vInteger = :vInteger + 1;
INSERT INTO test VALUES('Test');
END;
ELSE
set :vInteger = :vInteger - 1;
See Also
3-164
Grammar Statements
IN
Remarks
Use the IN operator to test whether the result of the outer query is
included in the result of the subquery. The result table for the
statement includes only rows the outer query returns that have a
related row from the subquery.
Examples
The following example lists the names of all students who have taken
Chemistry 408:
SELECT p.First_Name + '
' +
p.Last_Name
3-165
INSERT
This statement inserts column values into one table.
Syntax
values-clause
| query-specification
values-clause ::= VALUES ( expression [ , expression ]... )
| DEFAULT VALUES
Remarks
Decimal
Money
NumericSA
NumericSTS
Timestamp
Numeric
3-166
Grammar Statements
CURTIME(),
CURDATE() and
NOW() variables
Using Default
Values
Nullable
NULL
As defined
Not NULL
As defined
Pre-v2000
Nullable
As defined
3-167
Examples
3-168
Grammar Statements
INSERT INTO Course(Name, Description, Credit_Hours,
Dept_Name)
VALUES ('ENG 409', 'Creative Writing II', 3,
'English')
INSERT INTO Course(Name, Description, Credit_Hours,
Dept_Name)
VALUES ('MAT 307', 'Probability II', 4,
'Mathematics')
t1
t1
t1
t1
t1
DEFAULT VALUES
(c2) VALUES (DEFAULT)
VALUES (100, DEFAULT)
VALUES (DEFAULT, 'bcd')
VALUES (DEFAULT, DEFAULT)
SELECT * FROM t1
c1
c2
---------- ---------10
abc
10
abc
100
abc
3-169
bcd
abc
The following SQL code shows the use of DEFAULT with multiple
UPDATE values.
CREATE TABLE t2 (c1 INT DEFAULT 10,
c2 INT DEFAULT 20 NOT NULL,
c3 INT DEFAULT 100 NOT NULL)
INSERT INTO t2 VALUES (1, 1, 1)
INSERT INTO t2 VALUES (2, 2, 2)
SELECT * FROM t2
c1
c2
---------- ---------1
1
2
2
c3
---------1
2
3-170
Grammar Statements
SELECT * FROM t2
c1
c2
---------- ---------1
1
10
20
c3
---------1
100
The following example shows what occurs when you use INSERT for
IDENTITY columns and columns with default values.
CREATE
INSERT
INSERT
INSERT
INSERT
INSERT
SELECT
3-171
3-172
Grammar Statements
JOIN
You can specify a single table or view, multiple tables, or a single view
and multiple tables. When you specify more than one table, the
tables are said to be joined.
Syntax
[ OUTER ]
outer-join-definition ::= table-reference outer-join-type JOIN table-reference
ON search-condition
outer-join-type ::= LEFT [ OUTER ] | RIGHT [ OUTER ] | FULL [
OUTER ]
3-173
The syntax in the previous section includes but goes beyond the
ODBC syntax in the Microsoft ODBC Programmers Reference.
Furthermore, the vendor string escape sequence at the beginning
and end of the left outer join does not change the core syntax of the
outer join.
The Pervasive PSQL database engine accepts outer join syntax
without the vendor strings. However, for applications that want to
comply with ODBC across multiple databases, the vendor string
construction should be used. Because ODBC vendor string outer
joins do not support more than two tables, it may be necessary to use
the syntax shown following Table 3-13 on page 3-175.
Examples
3-174
The following four tables are used in the examples in this section.
Grammar Statements
LastName
DeptID
EmpID
Franky
Avalon
D103
E1
Gordon
Lightfoot
D102
E2
Lawrence
Welk
D101
E3
Bruce
Cockburn
D102
E4
LocID
Name
D101
L1
TV
D102
L2
Folk
Street
E1
E2
14 Young St.
Name
L1
PlanetX
L2
PlanetY
3-175
Dept
FirstName
LastName
DeptID
EmpID
DeptID
LocID
Name
Franky
Avalon
D103
E1
NULL
NULL
NULL
Gordon
Lightfoot
D102
E2
D102
L2
Folk
Lawrence
Welk
D101
E3
D101
L1
TV
Bruce
Cockburn
D102
E4
D102
L2
Folk
Notice the NULL entry for Franky Avalon in the table. That is
because no DeptID of D103 was found in the Dept table. In a
standard (INNER) join, Franky Avalon would have been dropped
from the result set altogether.
Algorithm
The algorithm that the Pervasive PSQL Engine uses for the previous
example is as follows:
taking the left table, traverse the right table, and for every case where
the ON condition is TRUE for the current right table row, return a
result set row composed of the appropriate right table row appended
to the current left-table row.
If there is no right table row where the ON condition is TRUE, (it is
FALSE for all right table rows given the current left table row), create
a row instance of the right table with all column values NULL.
That result set, combined with the current left-table row for each
row, is indexed in the returned result set. The algorithm is repeated
for every left table row to build the complete result set. In the simple
two-way left outer join shown previously, Emp is the left table and
Dept is the right table.
3-176
Grammar Statements
With radiating left outer joins, all other tables are joined onto one
central table. In the following example of a three-way radiating left
outer join, Emp is the central table and all joins radiate from that
table.
SELECT * FROM (Emp LEFT OUTER JOIN Dept ON Emp.DeptID =
Dept.DeptID) LEFT OUTER JOIN Addr ON Emp.EmpID =
Addr.EmpID
Dept
Addr
First
Name
Last
Name
Dept
ID
Emp
ID
Dept
ID
Loc
ID
Name
Emp
ID
Street
Franky
Avalon
D103
E1
NUL
L
NUL
L
NULL
E1
101
Mem
Lane
Gordon
Lightfoot
D102
E2
D102
L2
Folk
E2
14
Young St
Lawren
ce
Welk
D101
E3
D101
L1
TV
NUL
L
NULL
Bruce
Cockbur
n
D102
E4
D101
L1
TV
NUL
L
NULL
In a chaining left outer join, one table is joined to another, and that
table, in turn, is joined to another. The following example illustrates
a three-way chaining left outer join:
3-177
Dept
Loc
First
Name
Last
Name
Dept
ID
Emp
ID
Dept
ID
Loc
ID
Name
Loc
ID
Name
Franky
Avalon
D103
E1
NULL
NULL
NULL
NULL
NULL
Gordon
Lightfoot
D102
E2
D102
L2
Folk
L2
Planet
Y
Lawrence
Welk
D101
E3
D101
L1
TV
L1
Planet
X
Bruce
Cockbur
n
D102
E4
D101
L1
TV
L1
Planet
X
3-178
Grammar Statements
Dept
Addr
First
Name
Last
Name
Dept
ID
Emp
ID
Dept
ID
Loc
ID
Name
Emp
ID
Street
Franky
Avalon
D103
E1
NULL
NULL
NULL
E1
101
Mem
Lane
Gordon
Lightfoot
D102
E2
D102
L2
Folk
E2
14
Young
St
Lawrence
Welk
D101
E3
D101
L1
TV
NULL
NULL
Bruce
Cockburn
D102
E4
D101
L1
TV
NULL
NULL
This query returns the same results as shown in Table 3-16, assuming
there are no NULL values for EmpID in Emp and EmpID is a unique
valued column. This query, however, is not optimized as well as the
one show for Table 3-16 and can be much slower.
See Also
3-179
LEAVE
Remarks
Examples
See Also
IF on page 3-163
LOOP on page 3-183
3-180
Grammar Statements
LIKE
LIKE allows pattern matching within character-based column data.
Syntax
Remarks
Purpose
Percent sign %
Underscore _
Back slash \
Flags the following wildcard character as a literal character, indicating that you want
to match the actual wildcard character itself. To match a back slash, enter two back
slashes. For example, to match %, the pattern should specify \%0.
Two single quotes without a space in between them must be used to match a single
quote that is part of the result string. For example, if a row in the database contains
the value Jims house, you can match this pattern by specifying LIKE Jims
house in the WHERE clause. A double-quote (") is not a special character within
the pattern string, and can be used like any letter or digit.
Examples
This example matches all column values that are five characters long
and have abc as the middle three characters:
SELECT Building_Name FROM Room WHERE Building_Name LIKE
'_abc_'
This example matches all column values that contain a back slash:
SELECT Building_Name FROM Room where Building_Name LIKE
'%\\%'
3-181
This example matches all column values except those that begin with
a percent sign:
SELECT Building_Name FROM Room where Building_Name NOT
LIKE '\%%'
This example matches all column values that contain one or more
single-quotes:
SELECT Building_Name FROM Room where Building_Name LIKE
'%''%'
This example matches all column values where the second character
is a double-quote:
SELECT Building_Name FROM Room where Building_Name LIKE
'_"%'
This example creates a stored procedure that returns any rows where
the Building_Name column contains the characters stored in the
input variable :rname and where the Type column contains the
characters stored in the input variable :rtype.
CREATE PROCEDURE room_test(IN :rname CHAR(20), IN :rtype
CHAR(20))
RETURNS(Building_Name CHAR(25), Type CHAR(20));
BEGIN
DECLARE :like1 CHAR(25);
DECLARE :like2 CHAR(25);
SET :like1 = '%' + :rname + '%';
SET :like2 = '%' + :rtype + '%';
SELECT Building_Name, Type FROM Room WHERE Building_
Name LIKE :like1 AND Type LIKE :like2;
END;
3-182
Grammar Statements
LOOP
Remarks
Examples
See Also
3-183
NOT
Remarks
Using the NOT keyword with the EXISTS keyword allows you to test
whether rows do not exist in the result of the subquery. For every row
the outer query evaluates, Pervasive PSQL tests for the existence of a
related row from the subquery. Pervasive PSQL excludes from the
statement's result table each row from the outer query that
corresponds to a related row from the subquery.
Including the NOT keyword along with the IN operator allows you
to test whether the result of the outer query is not included in the
result of the subquery. The result table for the statement includes
only rows the outer query returns that do not have a related row from
the subquery.
Examples
See Also
3-184
Grammar Statements
OPEN
Remarks
Syntax
OPEN cursor-name
cursor-name ::= user-defined-name
Examples
ORDER BY ID;
OPEN cursor1;
FETCH cursor1 INTO :CourseName;
CLOSE cursor1;
END
See Also
3-185
PARTIAL
Remarks
3-186
Grammar Statements
PRIMARY KEY
Remarks
name before you can add a primary key or conduct any other
referential integrity (RI) operation.
Include PRIMARY KEY in the ADD clause with the ALTER TABLE
statement to add a primary key to a table definition.
Before adding the primary key, you must ensure that the columns in
the primary key column list are defined as NOT NULL. A primary
key is a unique index and can be created only on not nullable
columns.
If a unique index on not nullable columns already exists, the ADD
PRIMARY KEY does not create another unique index. Instead, the
existing unique index is promoted to a primary key. For example, the
following statements would promote the named index T1_C1C2 to
be a primary key.
CREATE TABLE t1 (c1 INT NOT NULL, c2 CHAR(10) NOT NULL)
CREATE UNIQUE INDEX t1_c1c2 ON t1(c1,c2)
ALTER TABLE t1 ADD PRIMARY KEY(c1, c2)
3-187
Examples
See Also
3-188
Grammar Statements
PRINT
Remarks
Examples
See Also
3-189
PUBLIC
Remarks
You can include the PUBLIC keyword in the FROM clause to revoke
the Create Table right from all the users to whom the right was not
explicitly assigned.
Include a FROM clause to specify the group or user from whom you
are revoking rights. You can specify a single name or a list of names,
or you can include the PUBLIC keyword to revoke access rights from
all users whose rights are not explicitly assigned.
Examples
This statement assigns the Select right on the Course table to all users
defined in the dictionary. If you later revoke the Select right from the
PUBLIC group, only users who are granted the Select right explicitly
can access the table.
The following statement includes the PUBLIC keyword to grant the
Create Table right to all the users defined in the dictionary:
GRANT CREATETAB TO PUBLIC
See Also
3-190
Grammar Statements
RELEASE SAVEPOINT
Use the RELEASE SAVEPOINT statement to delete a savepoint.
Syntax
Remarks
::= user-defined-name
Examples
3-191
3-192
Grammar Statements
RESTRICT
Remarks
See Also
3-193
REVOKE
REVOKE deletes user IDs and removes permissions to specific users
in a secured database. You can use the REVOKE statement to revoke
CREATE TABLE, CREATE VIEW, and CREATE PROCEDURE
privileges.
Syntax
ALL
3-194
Grammar Statements
CREATE TABLE
CREATETAB
CREATE VIEW
CREATEVIEW
CREATE PROCEDURE
CREATESP
The following table shows which permissions are removed if you use
the ALL key word.
Table 3-19 Permissions Removed with ALL Key Word by Object Type
Permission Removed
by ALL
Table
View
ALTER
DELETE
INSERT
REFERENCES
SELECT
UPDATE
Stored Procedure
EXECUTE
Examples
The following statement revokes all these privileges from dannyd for
table Class.
REVOKE ALL ON Class FROM 'dannyd'
3-195
See Also
3-196
Grammar Statements
ROLLBACK
ROLLBACK returns the database to the state it was in before the
current transaction began. This statement releases the locks acquired
since the last SAVEPOINT or START TRANSACTION.
The ROLLBACK TO SAVEPOINT statement rolls back the
transaction to the specified savepoint.
Syntax
Remarks
Examples
3-197
See Also
3-198
Grammar Statements
SAVEPOINT
SAVEPOINT defines a point in a transaction to which you can roll
back.
Syntax
SAVEPOINT savepoint-name
savepoint-name ::= user-defined-name
Remarks
Examples
3-199
3-200
Grammar Statements
INTO variable |
search-condition ]
search-condition ]
]... ] ]
Examples
See Also
3-201
SELECT
Retrieves specified information from a database. A SELECT
statement creates a temporary view.
Syntax
OUTER ]
table-hint ::= INDEX ( index-value [ , index-value ]... )
index-value ::= 0 | index-name
index-name
3-202
::= user-defined-name
Grammar Statements
join-definition ::= table-reference [ join-type ] JOIN table-reference ON searchcondition
[ OUTER ]
table-subquery ::= query-specification [ [ UNION [ ALL ]
query-specification ]... ]
search-condition ::= search-condition AND search-condition
| search-condition OR search-condition
| NOT search-condition
| ( search-condition )
| predicate
predicate ::= expression [ NOT ] BETWEEN expression AND expression
IS [ NOT ] NULL
| expression + expression
| expression * expression
| expression / expression
| expression & expression
| expression | expression
| expression ^ expression
| ( expression )
| -expression
3-203
else_expression ::=
3-204
see
Grammar Statements
Remarks
FOR UPDATE
SELECT FOR UPDATE locks the row or rows within the table that is
selected by the query. The record locks are released when the next
COMMIT or ROLLBACK statement is issued.
To avoid contention, SELECT FOR UPDATE locks the rows as they
are retrieved.
SELECT FOR UPDATE takes precedence within a transactions if
statement level SQL_ATTR_CONCURRENCY is set to SQL_
CONCUR_LOCK. If SQL_ATTR_CONCURRENCY is set to SQL_
CONCUR_READ_ONLY, the database engine does not return an
error.
SELECT FOR UPDATE does not support a WAIT or NOWAIT key
word. SELECT FOR UPDATE returns status code 84: The record or
page is locked if it cannot lock the rows within a brief period (20 retries).
Constraints
3-205
GROUP BY
In addition to supporting a GROUP BY on a column-list, Pervasive
PSQL supports a GROUP BY on an expression-list or on any
expression in a GROUP BY expression-list. See GROUP BY on
page 3-160 for more information on GROUP BY extensions.
HAVING is not supported without GROUP BY.
Result sets and stored views generated by executing SELECT
statements with any of the following characteristics are read-only
(they cannot be updated). That is, a positioned UPDATE, a
positioned DELETE and an SQLSetPos call to add, alter or delete
data is not allowed on the result set or stored view if:
The view uses the UNION operator and UNION ALL is not
specified or all SELECT statements do not reference the same
table:
SELECT c1 FROM t1 UNION SELECT c1 FROM t1
SELECT c1 FROM t1 UNION ALL SELECT c1 FROM t2
3-206
Grammar Statements
3-207
comparison
quantified
in
exists
correlated
expression
3-208
Grammar Statements
>
(greater than)
<=
(less than or
equal to)
>=
(greater than
or equal to)
=
(equals)
<>
(not equal)
!=
(not equal)
LIKE
IN
NOT IN
Optimization
Left-hand subquery behavior has been optimized for IN, NOT IN,
and =ANY in cases where the subquery is not correlated and any join
condition is an outer join. Other conditions may not be optimized.
Here is an example of a query that meets these conditions:
SELECT count(*) FROM person WHERE id IN
(SELECT faculty_id FROM class)
UNION in Subquery
Table Subqueries
3-209
Table Hint
The table hint functionality allows you to specify which index, or
indexes, to use for query optimization. A table hint overrides the
default query optimizer used by the database engine.
If the table hint specifies INDEX(0), the engine performs a table scan
of the associated table. (A table scan reads each row in the table
rather than using an index to locate a specific data element.)
If the table hint specifies INDEX(index-name), the engine uses
index-name to optimize the table based on restrictions of any JOIN
conditions, or based on the use of DISTINCT, GROUP BY, or
ORDER BY. If the table cannot be optimized on the specified index,
the engine attempts to optimize the table based on any existing
index.
If you specify multiple index names, the engine chooses the index
that provides optimal performance or uses the multiple indexes for
OR optimization. An example helps clarify this. Suppose that you
have the following:
CREATE
CREATE
CREATE
SELECT
AND
The engine uses both ndx1 and ndx2 to optimize on (c1 = 1 OR c2 >
1).
The order in which the multiple index names appear in the table hint
does not matter. The database engine chooses from the specified
indexes the one(s) that provides for the best optimization.
Duplicate index names within the table hint are ignored.
3-210
Grammar Statements
Typically, table hints are not required because the database query
optimizer usually picks the best optimization method.
Restrictions
Incorrect SQL:
Returns:
SQL_ERROR
szSqlState:
37000
Message:
Incorrect SQL:
Returns:
SQL_SUCCESS_WITH_INFO
szSqlState:
01000
Message:
Incorrect SQL:
Returns:
SQL_ERROR
szSqlState:
S1000
Message:
3-211
Incorrect SQL:
Returns:
SQL_ERROR
szSqlState:
S0012
Message:
Examples
Incorrect SQL:
Returns:
SQL_ERROR
szSqlState:
37000
Message:
This simple SELECT statement retrieves all the data from the Faculty
table.
SELECT * FROM Faculty
This statement retrieves the data from the person and the faculty
table where the id column in the person table is the same as the id
column in the faculty table.
SELECT Person.id, Faculty.salary FROM Person, Faculty
WHERE Person.id = Faculty.id
3-212
Grammar Statements
FOR UPDATE
The following example uses table t1 to demonstrate the use of FOR
UPDATE. Assume that t1 is part of the DEMODATA sample
database. The stored procedure creates a cursor for the SELECT FOR
UPDATE statement. A loop fetches each record from t1 and, for
those rows where c1=2, sets the value of c1 to four.
The procedure is called by passing the value 2 as the IN parameter.
The example assumes that two users, A and B, are logged in to
DEMODATA. User A performs the following:
DROP TABLE t1
CREATE TABLE t1 (c1 INTEGER, c2 INTEGER)
INSERT INTO t1 VALUES (1,1)
INSERT INTO t1 VALUES (2,1)
INSERT INTO t1 VALUES (1,1)
INSERT INTO t1 VALUES (2,1)
CREATE PROCEDURE p1 (IN :a INTEGER)
AS
BEGIN
DECLARE :b INTEGER;
DECLARE :i INTEGER;
DECLARE c1Bulk CURSOR FOR SELECT * FROM t1 WHERE
c1 = :a FOR UPDATE;
START TRANSACTION;
OPEN c1Bulk;
BulkLinesLoop:
LOOP
FETCH NEXT FROM c1Bulk INTO :i;
IF SQLSTATE = '02000' THEN
LEAVE BulkLinesLoop;
END IF;
UPDATE SET c1 = 4 WHERE CURRENT OF c1Bulk;
END LOOP;
CLOSE c1Bulk;
3-213
3-214
Grammar Statements
Now assume that User A issues call SQLEndTran with option SQL_
COMMIT. The two records where c1 = 2 are unlocked.
User B could now issue call SQLExecDirect UPDATE t1 SET
c1=3 WHERE c1=2 and change the values for c1.
approximate-numeric-literal
SELECT * FROM results WHERE quotient =-4.5E-2
INSERT INTO results (quotient) VALUES (+5E7)
between-predicate
The syntax expression1 BETWEEN expression2 and expression3
returns TRUE if expression1 >= expression2 and expression1<=
expression3. FALSE is returned if expression1 >= expression3, or is
expression1 <= expression2.
Expression2 and expression3 may be dynamic parameters (for
example, SELECT * FROM emp WHERE emp_id BETWEEN ? AND ?)
The next example retrieves the first names from the person table
whose ID fall between 10000 and 20000.
SELECT First_name FROM Person WHERE ID BETWEEN 10000 AND
20000
correlation-name
Both table and column correlation names are supported.
The following example selects data from both the person table and
the faculty table using the aliases T1 and T2 to differentiate between
the two tables.
SELECT * FROM Person t1, Faculty t2 WHERE t1.id = t2.id
The correlation name for a table name can also be specified in using
the FROM clause, as seen in the following example.
SELECT a.Name, b.Capacity FROM Class a, Room b
WHERE a.Room_Number = b.Number
3-215
exact-numeric-literal
SELECT car_num, price FROM cars WHERE car_num =49042 AND
price=49999.99
in-predicate
This selects the records from table Person table where the first names
are Bill and Roosevelt.
SELECT * FROM Person WHERE First_name IN ('Roosevelt',
'Bill')
set-function
The following example selects the minimum salary from the Faculty
table.
SELECT MIN(salary) FROM Faculty
date-literal
Date constants may be expressed in SQL statements as a character
string or embedded in a vendor string. SQL_CHAR and the vendor
string representation are treated as a value of type SQL_DATE. This
becomes important when conversions are attempted.
Pervasive PSQL partially supports extended SQL grammar, as
outlined in this function.
3-216
Grammar Statements
The next two statements return all the classes whose start date is after
1995-06-05.
SELECT * FROM Class WHERE Start_Date > '1995-06-05'
SELECT * FROM Class WHERE Start_Date > {d '1995-06-05'}
time-literal
The following two statements retrieve records from the class table
where the start time for the classes is 14:00:00.
SELECT * FROM Class WHERE Start_time = '14:00:00'
SELECT * FROM Class WHERE Start_time = {t '14:00:00'}
timestamp-literal
Timestamp constants may be expressed in SQL statements as a
character string or embedded in a vendor string. Pervasive PSQL
treats the character string representation as a string of type SQL_CHAR
and the vendor string representation as a value of type SQL_
TIMESTAMP. Pervasive PSQL partially supports extended SQL
grammar, as outlined in this function.
The next two statements retrieve records from the Billing table where
the start day and time for the log is 1996-03-28 at 17:40:49.
SELECT * FROM Billing WHERE log = '1996-03-28
17:40:49.0000000'
3-217
Pervasive PSQL supports the following time literal format: 'YYYYMM-DD HH:MM:SS.SSSSSSS'. Note that Pervasive PSQL ignores
the fractional seconds when processing Timestamp values, but the
MKDE does not.
string-literal
Literal strings are represented as single-quoted strings. If the string
itself contains a single-quote or apostrophe, the character must be
preceded by another single-quote.
SELECT * FROM t1 WHERE c1 = Robertas Restaurant
SELECT STREET FROM address WHERE city LIKE San%
date arithmetic
SELECT * FROM person P, Class C WHERE p.Date_Of_Birth <
' 1973-09-05' AND c.Start_date >{d '1995-05-08'} + 30
IF
The IF system scalar function provides conditional execution based
on the truth value of a condition
This expression prints the column header as Prime1 and amount
owed as 2000 where the value of the column amount_owed is 2000
or it prints a 0 if the value of the amount_owed column is not equal
to 2000.
SELECT Student_ID, Amount_Owed,
IF (Amount_Owed = 2000, Amount_Owed, Convert(0, SQL_
DECIMAL)) Prime1
3-218
Grammar Statements
FROM Billing
From table Class, the following example prints the value in the
Section column if the section is equal to 001, else it prints xxx
under column header Prime1
Under column header Prime2, it prints the value in the Section
column if the value of the section column is equal to 002, or else it
prints yyy.
SELECT ID, Name, Section,
IF (Section = '001', Section, 'xxx') Prime1,
IF (Section = '002', Section, 'yyy') Prime2
FROM Class
You can combine header Prime1 and header Prime2 by using nested
IF functions. Under column header Prime, the following query
prints the value of the Section column if the value of the Section
column is equal to 001 or 002. Otherwise, it print xxx.
SELECT ID, Name, Section,
IF (Section = '001', Section, IF(Section = '002',
Section, 'xxx')) Prime
FROM Class
Multi-database Join
When needed, a database name may be prepended to an aliased table
name in the FROM clause, to distinguish among tables from two or
more different databases that are used in a join.
All of the specified databases must be serviced by the same database
engine. They do not need to reside on the same physical volume. The
current database may be secure or non-secure, but all other
databases in the join must be non-secure. With regard to Referential
Integrity, all RI keys must exist within the same database.
Literal database names are not permitted in the select-list or in the
WHERE clause. If you wish to refer to specific columns in the selectlist or in the WHERE clause, you must use an alias for each specified
table. See examples.
Assume two separate databases, accounting and customers, exist
on the same server. You can join tables from the two databases using
table aliases and SQL syntax similar to the following example:
3-219
3-220
Grammar Statements
RIGHT OUTER JOIN. Change the query for LEFT OUTER JOIN to
include a RIGHT OUTER JOIN instead. The difference is that the all
non-matching rows from the right table, in this case Student, show
up even if no GPA is present. However, since all rows in the Student
table have GPAs, all rows are fetched.
SELECT Last_Name,Left(First_Name,1) AS First_
Initial,Cumulative_GPA AS GPA FROM Person
RIGHT OUTER JOIN Student ON Person.ID=Student.ID
ORDER BY Cumulative_GPA DESC, Last_Name
Cartesian join
A Cartesian join is the matrix of all possible combinations of the
rows from each of the tables. The number of rows in the Cartesian
product equals the number of rows in the first table times the
number of rows in the second table.
Assume you have the following tables in your database:
Table 3-20 Addr Table
EmpID
Street
E1
E2
14 Young St.
Name
L1
PlanetX
L2
PlanetY
3-221
Street
LocID
Name
E1
L1
PlanetX
E1
L2
PlanetY
E2
14 Young St
L1
PlanetX
E2
14 Young St
L2
PlanetY
DISTINCT
You can use DISTINCT with SUM, AVG, COUNT, MIN, and MAX
(but it does not change results with MIN and MAX). DISTINCT
eliminates duplicate values before calculating the sum, average or
count.
Suppose you want to know the salaries for different departments
including the minimum, maximum and salary, and you want to
remove duplicate salaries. The following statement would do this,
excluding the computer science department:
SELECT dept_name, MIN(salary), MAX(salary), AVG(DISTINCT
salary) FROM faculty WHERE dept_name<>'computer science'
GROUP BY dept_name
TOP
You may limit the number of rows returned by a single SELECT
statement by using the keyword TOP in the statement and specifying
a value for the maximum number of rows to return.
The specified number of rows must be a literal positive number. It is
defined as a 32-bit unsigned integer.
3-222
Grammar Statements
Dynamic
Forward-only
Static
Static
Forward-only
No change
Forward-only
No change
No change
SET ROWCOUNT = 5;
SELECT TOP 10 * FROM person;
-- returns 5 rows
3-223
Incorrect Examples
The following SELECT statements generate error messages, because
the view defined contains a TOP clause, and thus cannot be involved
in a join.
CREATE VIEW v1 (c1) AS SELECT TOP 10 id FROM person
SELECT * FROM v1 INNER JOIN person ON v1.c1 = person.id
-- returns an error message
Table Subquery
The following example provides the last name of the student and the
amount the student owes for all students with an ID greater than
714662900.
3-224
Grammar Statements
SELECT p_last_name, b_owed FROM
(SELECT id, last_name FROM person) p (p_id, p_last_
name),
(SELECT student_id, SUM (amount_owed) FROM billing
GROUP BY student_id) b (b_id, b_owed)
WHERE p.p_id = b.b_id AND p.p_id > 714662900
ORDER BY p_last_name ASC
Table Hints
The examples for table hints use table t1, t2, or both. You can create
and populate the example tables with the following SQL.
DROP TABLE t1
CREATE TABLE t1 (c1 INTEGER, c2 INTEGER)
INSERT INTO t1 VALUES (1,10)
INSERT INTO t1 VALUES (1,10)
INSERT INTO t1 VALUES (2,20)
INSERT INTO t1 VALUES (2,20)
INSERT INTO t1 VALUES (3,30)
INSERT INTO t1 VALUES (3,30)
CREATE INDEX it1c1 ON t1 (c1)
CREATE INDEX it1c1c2 ON t1 (c1, c2)
CREATE INDEX it1c2 ON t1 (c2)
CREATE INDEX it1c2c1 ON t1 (c2, c1)
DROP TABLE t2
CREATE TABLE t2 (c1 INTEGER, c2 INTEGER)
INSERT INTO t2 VALUES (1,10)
INSERT INTO t2 VALUES (1,10)
INSERT INTO t2 VALUES (2,20)
INSERT INTO t2 VALUES (2,20)
INSERT INTO t2 VALUES (3,30)
INSERT INTO t2 VALUES (3,30)
Note that certain restrictions apply to the use of table hints. See
Restrictions on page 3-211 for SQL examples.
3-225
3-226
Grammar Statements
Contrast this with the following statement, which does not use a
table hint and optimizes on index it1c1.
SELECT * FROM t2 INNER JOIN t1 ON t1.c1 = t2.c1
Contrast this with the following example which also performs a table
scan of table t1. However, because no JOIN clause is used, the
statement uses a temporary table join.
SELECT * FROM t2, t1 WITH (INDEX(0)) WHERE t1.c1 = t2.c1
See Also
3-227
SET ANSI_PADDING
The SET ANSI_PADDING statement allows the relational interface
to handle CHAR data types padded with NULLs (binary zeros).
CHAR is defined as a character data type of fixed length.
Pervasive PSQL supports two interfaces: transactional and relational.
The transactional interface allows a CHAR to be padded with
NULLs. The relational interface conforms to the ANSI standard for
padding, which specifies that a CHAR be padded with spaces. For
example, by default, a CHAR column created with a CREATE TABLE
statement is always padded with spaces.
An application that uses both interfaces may need to process strings
padded with NULLs.
Syntax
SET ANSI_PADDING=<ON|OFF>
Remarks
The default value is ON, meaning that strings padded with spaces are
inserted into CHARs. Trailing spaces are considered as insignificant
in logical expression comparisons. Trailing NULLs are considered as
significant in comparisons.
If set to OFF, the statement means that strings padded with NULLs
are inserted into CHARs. Both trailing NULLs and trailing spaces are
considered as insignificant in logical expression comparisons.
The following string functions support NULL padding:
CHAR_LENGTH
CONCAT
LCASE or LOWER
LEFT
LENGTH
LOCATE
LTRIM
POSITION
REPLACE
REPLICATE
RIGHT
RTRIM
STUFF
SUBSTRING
UCASE or UPPER
Restrictions
The following restrictions apply to SET ANSI_PADDING:
3-228
Grammar Statements
Examples
The following example shows the results of string padding using the
INSERT statement with SET ANSI_PADDING set to ON and to
OFF.
DROP TABLE t1
CREATE TABLE t1 (c1 CHAR(4))
SET ANSI_PADDING = ON
INSERT INTO t1 VALUES (a) -- string a = a\0x20\0x20\0x20
INSERT INTO t1 VALUES (a + CHAR(0) + CHAR(0) + CHAR(0))
-- string a = a\0x00\0x00\0x00
DROP TABLE t1
CREATE TABLE t1 (c1 CHAR(4))
SET ANSI_PADDING = OFF
INSERT INTO t1 VALUES (a) -- string a = a\0x00\0x00\0x00
INSERT INTO t1 VALUES (a + CHAR(32) + CHAR(32) +
CHAR(32)) -- string a = a\0x20\0x20\0x20
The following example shows the results of string padding using the
UPDATE statement with SET ANSI_PADDING set to ON and to
OFF.
DROP TABLE t1
CREATE TABLE t1 (c1 CHAR(4))
SET ANSI_PADDING = ON
UPDATE t1 SET c1 = a -- all rows for c1 = a\0x20\0x20\0x20
UPDATE t1 SET c1 = a + CHAR(0) + CHAR(0) + CHAR(0)
-- all rows for c1 = a\0x00\0x00\0x00
DROP TABLE t1
CREATE TABLE t1 (c1 CHAR(4))
SET ANSI_PADDING = OFF
UPDATE t1 SET c1 = a -- all rows for c1 = a\0x00\0x00\0x00
UPDATE t1 SET c1 = a + CHAR(32) + CHAR(32) + CHAR(32)
-- all rows for c1 = a\0x20\0x20\0x20
3-229
See Also
3-230
Grammar Statements
SET CACHED_PROCEDURES
The SET CACHED_PROCEDURES statement specifies the number
of stored procedures that the database engine caches in memory for
an SQL session.
Syntax
Remarks
The value of number can be any whole number in the range zero
through approximately two billion. The database engine
automatically defaults to 50. Each session can change its number of
cached procedures by issuing the SET statement.
The companion statement to SET CACHED_PROCEDURES is SET
PROCEDURES_CACHE.
If you set both SET statements to zero, the database engine does
not cache stored procedures. In addition, the engine removes
any existing cache used for stored procedures. That is, the engine
flushes from cache all stored procedures that were cached before
you set both statements to zero.
If you set only one of the statements to a value, either zero or a
nonzero value, the other statement is implicitly set to zero. The
statement implicitly set to zero is ignored. For example, if you
are only interested in caching 70 procedures and are not
concerned with the amount of memory, set CACHED_
PROCEDURES to 70. The database engine implicitly sets
PROCEDURES_CACHE to zero, which ignores the setting.
3-231
Registry Setting
In addition to the SET statement, the number of cached procedures
can be specified with a registry setting. The registry settings apply to
all sessions and provides a convenient way to set an initial value. Each
session can override the registry setting for that particular session by
using the SET statement.
The registry setting applies to all server platforms on which Pervasive
PSQL Server is supported. You must manually modify the registry
setting. On Windows, use the registry editor provided with the
operating system. On Linux, you can use the psregedit utility.
If the registry setting is not specified, the database engine
automatically defaults to 50.
3-232
Grammar Statements
Caching Exclusions
A stored procedure is not cached, regardless of the cache setting(s),
for any of the following:
Examples
The following example specifies that you do not want to cache stored
procedures and that any existing procedures cache will be removed.
SET CACHED_PROCEDURES = 0
SET PROCEDURES_CACHE = 0
3-233
The following example specifies that you want to cache 120 stored
procedures and ignore the amount of memory used for the cache.
SET CACHED_PROCEDURES = 120
3-234
Grammar Statements
SET DECIMALSEPARATORCOMMA
The ODBC database engine by default displays decimal data using a
period (.) as the separator between ones and tenths (for example,
100.95). The SET DECIMALSEPARATORCOMMA statement
allows you to specify that results should be displayed using a comma
to separate ones and tenths (for example, 100,95).
As with all SET statements, the effects of this statement apply to the
remainder of the current database session, or until another SET
DECIMALSEPARATORCOMMA statement is issued.
Syntax
SET DECIMALSEPARATORCOMMA=<ON|OFF>
Remarks
The default value is OFF, meaning that the period is used as the
default decimal separator.
In locales where the comma is used as the decimal separator, decimal
data can be entered using a comma or a period as the separator
(literal values that use the comma as the separator must be enclosed
in single quotes, for example: 123,43). When the data is returned,
however (as in the results of a SELECT statement), it is always
displayed using a period unless SET
DECIMALSEPARATORCOMMA=ON has been specified.
Likewise, if your database contains data that was entered using the
period as the decimal separator, you can choose to specify the
comma as the separator for output and display by using this
statement.
This command affects output and display only. It has no effect on
values being inserted, updated, or used in a comparison.
Examples
c1
c2
------- ------102.34 95.234
3-235
c1
c2
------- ------102,34 95,234
the client and/or server operating system locale settings are set to
a locale that uses the comma as the separator. For example, if you
have U.S. locale settings on both your client and server, you will
receive an error if you attempt to run this example.
CREATE TABLE t1 (c1 real, c2 real)
INSERT INTO t1 VALUES (102,34, 95,234)
SELECT * FROM t1
Results:
c1
c2
------- ------102.34 95.234
SET DECIMALSEPARATORCOMMA=ON
SELECT * FROM t1
Results:
c1
c2
------- ------102,34 95,234
See Also
3-236
Grammar Statements
SET DEFAULTCOLLATE
The SET DEFAULTCOLLATE statement specifies the collating
sequence file to use for all columns of data type CHAR, VARCHAR,
or LONGVARCHAR.
Syntax
Remarks
3-237
Examples
The path must be at least 1 character long and cannot exceed 255
characters.
Relative paths are allowed and are relative to the directory where
the DDFs are located. Relative paths and can contain a period
(current directory), double period (parent directory), slash, or
any combination of the three. Slash characters in relative paths
may be either forward (/) or backslash (\). You may mix the use
of the two types, if desired.
Universal naming convention (UNC) path names are permitted.
For default locations of Pervasive PSQL files, see Where are the
Pervasive PSQL v10 files installed? on page 7-2 in Getting Started
With Pervasive PSQL.
The following example sets a default collating sequence using the
upper.alt file supplied with Pervasive PSQL. A table, t1, is created
with three text columns and three columns not text. A SELECT
statement executes against Pervasive PSQL system tables to return
the ID, type, size, and attributes of the columns in t1. The result
shows that the three text columns have an attribute of UPPER.
SET DEFAULTCOLLATE = 'file_path\upper.alt'
DROP TABLE t1
CREATE TABLE t1 (c1 INT, c2 CHAR(10), c3 BINARY(10), c4
VARCHAR(10), c5 LONGVARBINARY, c6 LONGVARCHAR)
SELECT * FROM x$attrib WHERE xa$id in (SELECT xe$id FROM
x$field WHERE xe$file = (SELECT xf$id FROM x$file
WHERE xf$name = 't1'))
Xa$Id
=====
327
329
331
Xa$Type
=======
O
O
O
Xa$ASize
========
265
265
265
3-238
Xa$Attrs
========
UPPER
UPPER
UPPER
Grammar Statements
The following example continues with the use of table t1. An ALTER
TABLE statement changes the text column c2 from a CHAR to an
INTEGER. The result of the SELECT statement shows that now only
two columns are affected by the default collating.
ALTER TABLE t1 ALTER c2 INT
SELECT * FROM x$attrib WHERE xa$id in (SELECT xe$id FROM
x$field WHERE xe$file = (SELECT xf$id FROM x$file
WHERE xf$name = 't1'))
Xa$Id
=====
329
331
Xa$Type
=======
O
O
Xa$ASize
========
265
265
Xa$Attrs
========
UPPER
UPPER
Xa$Type
=======
O
O
O
Xa$ASize
========
265
265
265
Xa$Attrs
========
UPPER
UPPER
UPPER
See Also
3-239
SET OWNER
The SET OWNER statement allows you to specify one or more
owner names for use during the current database connection. An
owner name is assigned only through the transactional interface, not
through the relational interface. Note that no relationship exists
between an owner name and any system user name or database user
name. Think of an owner name as a simple file password that, if
assigned, is required to access a data file.
Syntax
Remarks
3-240
Grammar Statements
Examples
or
GRANT ALL ON inventory admin TO MASTER
See Also
3-241
SET PASSWORD
The SET PASSWORD statement provides the following
functionality for a secured database:
Syntax
The Master user can change the password for the Master user or
for another user.
A normal user (non-Master user) can change his or her logon
password to the database.
Remarks
Master
User-name refers to a user who can log on a Pervasive PSQL database, which may differ from the name
assigned to a user at the operating system level. For example, assume that Yogine is a user who can log on
to the operating system. Security is enabled on database DEMODATA and Yogine is added to DEMODATA
as a user named DeptMgr. The user-name required for this person to log on DEMODATA is DeptMgr.
3-242
Grammar Statements
Password Characteristics
Examples
3-243
See Also
3-244
Grammar Statements
SET PROCEDURES_CACHE
The SET PROCEDURES_CACHE statement specifies the amount of
memory for an SQL session that the database engine reserves as a
cache for stored procedures.
Syntax
Remarks
The value of megabytes can be any whole number in the range zero
to approximately two billion. The database engine automatically
defaults to 5 MB. Each session can change its amount of cache
memory by issuing the SET statement.
The companion statement to SET PROCEDURES_CACHE is SET
CACHED_PROCEDURES.
If you set both SET statements to zero, the database engine does
not cache stored procedures. In addition, the engine removes
any existing cache used for stored procedures. That is, the engine
flushes from cache all stored procedures that were cached before
you set both statements to zero.
If you set only one of the statements to a value, either zero or a
nonzero value, the other statement is implicitly set to zero. The
statement implicitly set to zero is ignored. For example, if you
are only interested in 30 MB as the amount of memory cached
and are not concerned with the number of procedures cached,
set PROCEDURES_CACHE to 30. The database engine
implicitly sets CACHED_PROCEDURES to zero, which ignores
the setting.
3-245
Registry Setting
In addition to the SET statement, the amount of memory reserved
for the cache can be specified with a registry setting. The registry
settings apply to all sessions and provides a convenient way to set an
initial value. Each session can override the registry setting for that
particular session by using the SET statement.
The registry setting applies to all server platforms on which Pervasive
PSQL Server is supported. You must manually modify the registry
setting. On Windows, use the registry editor provided with the
operating system. On Linux, you can use the psregedit utility.
If the registry setting is not specified, the database engine
automatically defaults to 5 MB.
3-246
Grammar Statements
Caching Exclusions
A stored procedure is not cached, regardless of the cache setting(s),
for any of the following:
Examples
The following example specifies that you do not want to cache stored
procedures and that any existing procedures cache will be removed.
SET CACHED_PROCEDURES = 0
SET PROCEDURES_CACHE = 0
3-247
The following example specifies that you want to set the amount of
cache memory to 80 MB and ignore the number of procedures that
may be cached.
SET PROCEDURES_CACHE = 80
3-248
Grammar Statements
SET ROWCOUNT
You may limit the number of rows returned by all subsequent
SELECT statements within the current session by using the keyword
SET ROWCOUNT.
The main difference between SET ROWCOUNT and TOP is that
TOP affects only the current statement, while SET ROWCOUNT
affects all statements issued during the current database session,
until the next SET ROWCOUNT or until the session is terminated.
Syntax
Remarks
See Also
3-249
SET SECURITY
The SET SECURITY statement allows the Master user to enable or
disable security for the database to which Master is logged on.
Syntax
Examples
The following example enables security for the database and sets the
Master password to mypasswd.
SET SECURITY = mypasswd
Remarks
You must be logged on as Master to set security. You can then assign
a password by using the SET SECURITY statement. No password is
required for Master to log an unsecured databased. A password must
be assigned to Master to enable security for the database.
SET SECURITY can be issued only when the session for the Master
user is the only current database connection. You can also set
security from the Pervasive PSQL Control Center (PCC). See To
turn on security using Pervasive PSQL Explorer on page 3-38 in
Pervasive PSQL User's Guide.
Note The SET SECURITY statement cannot be executed within
the SQL Editor. An error results if you try. For a database with
no security, the SQL Editor locks the dictionary files, which
prevents your setting the password. For a secure database, the
SQL Editor opens a second connection to the database files,
which prevents your disabling security.
3-250
Grammar Statements
User Permissions
See Also
3-251
Syntax
3-252
Grammar Statements
CURRENT_DATE(), CURRENT_
TIME(), CURRENT_TIMESTAMP()
CURRENT_DATE(), CURRENT_
TIME(), CURRENT_TIMESTAMP()
To convert a given local time value to UTC, you must subtract your
time zone displacement value from the local time value. In other
words,
UTC time = local time - time zone displacement
3-253
Displacement
UTC
10:10:15
Austin, Texas
US Central Standard
Time -06:00
10:10:15-(-06:00)=16:10:15 UTC
16:10:15
London
16:10:15-(+00:00)=16:10:15 UTC
22:10:15
Dhaka
+06:00
22:10:15-(+06:00)=16:10:15 UTC
Value
SELECT NOW()
2001-10-01 12:05:00.000000
displayed.
2001-10-01 18:05:00.000000
stored on disk.
SELECT * from t1
2001-10-01 12:05:00.000000
displayed.
SELECT CURRENT_TIMESTAMP()
2001-10-01 18:05:00.000000
displayed.
2001-10-01 18:05:00.000000
stored on disk.
SELECT * from t2
2001-10-01 12:05:00.000000
displayed.
3-254
Grammar Statements
In this example, no SET TIME ZONE statement has been issued yet,
and the computer on which the database engine is running has its
clock set to January 9, 2002, 16:35:03 CST (U.S.). Recall that
CURRENT_TIMESTAMP() and the other CURRENT_ functions
always return UTC time and/or date based on the system clock and
locale settings of the computer where the database engine is running.
SELECT CURRENT_TIMESTAMP(), NOW(),
CURRENT_TIME(), CURTIME(),
CURRENT_DATE(), CURDATE()
Results:
2002-01-09 22:35:03.0000000 2002-01-09 16:35:03.0000000
22:35:03
16:35:03
2002-01-09
2002-01-09
Note that the value of NOW() changed after the SET TIME ZONE
statement, but the value of CURRENT_TIMESTAMP() did not.
3-255
Results:
c1
c2
--------------------------- --------------------------2002-01-09 16:35:03.0000000 2002-01-09 16:35:03.0000000
c3
c4
c5
c6
-------- -------- ---------- ---------22:35:03 16:35:03 2002-01-09 2002-01-09
Results:
c1
c2
--------------------------- --------------------------2002-01-09 22:35:03.0000000 2002-01-09 22:35:03.0000000
c3
c4
c5
c6
-------- -------- ---------- ----------
3-256
Grammar Statements
Results:
2002-01-09 22:35:03.0000000 2002-01-10 08:35:03.0000000
22:35:03
08:35:03
2002-01-09
2002-01-10
INSERT INTO t1 SELECT CURRENT_TIMESTAMP(), NOW(),
CURRENT_TIME(), CURTIME(), CURRENT_DATE(), CURDATE()
SELECT * FROM t1
Results:
c1
c2
--------------------------- --------------------------2002-01-10 08:35:03.0000000 2002-01-10 08:35:03.0000000
c3
c4
c5
c6
-------- -------- ---------- ---------22:59:55 08:59:55 2002-01-09 2002-01-10
As you can see, the UTC time and date returned by CURRENT_
DATE() and CURRENT_TIME() are stored as literal values. Since
they are not TIMESTAMP values, no adjustment is made to these
values when they are retrieved from the database.
See Also
3-257
SET TRUEBITCREATE
The SET TRUEBITCREATE statement allows you to specify whether
the BIT data type can be indexed and can map to the LOGICAL
transactional data type.
Syntax
Remarks
The default is on. This means that the BIT data type is 1 bit, cannot
be indexed and is assigned a Pervasive PSQL type code of 16. When
of type code 16, BIT has no equivalent transactional data type to
which it maps.
For certain situations, such as compatibility with other DBMS
applications, you may want to map BIT to the LOGICAL data type
and be able to index the BIT data type. To do so, set
TRUEBITCREATE to off. This maps BIT to LOGICAL, which is a
1-byte data type of type code 7.
The creation mode remains in effect until it is changed by issuing the
statement again, or until the database connection is disconnected.
Because this setting is maintained on a per-connection basis,
separate database connections can maintain different creation
modes, even within the same application. Every connection starts
with the setting in default mode, where BITs are created with a
Pervasive PSQL type code of 16.
This feature does not affect existing BITs, only ones created after the
set statement is applied.
This setting can be toggled only by using SQL. It cannot be set using
the Pervasive PSQL Control Center. Note that Table Editor displays
the relational data types for columns (so the type is displayed as
BIT). If TRUEBITCREATE is set to off, Table Editor allows you
to index the BIT column.
Example
To toggle the setting and specify that new BITs should be created to
allow indexing, map to the LOGICAL transactional data type, and
have a type code of 7:
SET TRUEBITCREATE=OFF
3-258
Grammar Statements
SET TRUENULLCREATE
The SET TRUENULLCREATE statement turns on or off true NULLs
when you create new tables.
Syntax
Remarks
Pervasive PSQL v10 allows you to set the default format for creation
of tables with regard to NULL support. Normally, the product
creates new tables using the true NULL data record format, which
adds a NULL indicator byte to the beginning of every field. By
turning off this engine setting using an SQL statement, you can
create new tables that use the legacy NULL data record format that
was used in Pervasive.SQL 7.
The creation mode remains in effect until it is changed by issuing the
statement again, or until the connection is disconnected. Because
this setting is maintained on a per-connection basis, separate
database connections can maintain different creation modes, even
within the same application. Every connection starts with the setting
in default mode, where new tables are created with true NULL
support.
This feature does not affect existing tables or available column data
types. All tables are created using Pervasive PSQL data types. For
example, old data types such as NOTE or LVAR are not available for
use regardless of which type of NULL support is selected.
Also see the discussion about nullable data types under INSERT
on page 3-166.
This setting can be toggled only by using SQL. It cannot be set using
the Pervasive PSQL Control Center.
Examples
To toggle the setting and specify that new tables should be created
with legacy NULL support, use this SQL statement:
SET TRUENULLCREATE=OFF
To toggle the setting and return the engine to the default, which is
table creation with true NULL support, use this SQL statement:
SET TRUENULLCREATE=ON
3-259
SET
The SET statement assigns a value to a declared variable.
Syntax
Remarks
You must declare variables before you can set them. SET is allowed
only in stored procedures and triggers.
Examples
See Also
3-260
Grammar Statements
SIGNAL
Remarks
defined function.
Syntax
Examples
3-261
See Also
3-262
Grammar Statements
SQLSTATE
Remarks
See Also
3-263
START TRANSACTION
START TRANSACTION signals the start of a logical transaction and
must always be paired with a COMMIT or a ROLLBACK.
Syntax
START TRANSACTION
Sql-statements
COMMIT | ROLLBACK [WORK]
Remarks
3-264
Grammar Statements
See Also
3-265
UNION
Remarks
Aliases must differ from any table names and column names in the
query.
3-266
Grammar Statements
Examples
The next example lists the column id in the person table and the
faculty table including duplicate rows.
SELECT person.id FROM person UNION ALL SELECT faculty.id
from faculty
The next example lists the ID numbers of each student whose last
name begins with 'M' or who has a 4.0 grade point average. The
result table does not include duplicate rows and orders the result set
by the first column
SELECT Person.ID FROM Person WHERE Last_name LIKE M%
UNION SELECT Student.ID FROM Student WHERE Cumulative_
GPA = 4.0 ORDER BY 1
See Also
3-267
UNIQUE
Remarks
To specify that the index not allow duplicate values, include the
UNIQUE keyword. If the column or columns that make up the index
contains duplicate values when you execute the CREATE INDEX
statement with the UNIQUE keyword, Pervasive PSQL returns
Status Code 5 and does not create the index.
Note You should not include the UNIQUE keyword in the list of
index attributes following the column name you specify; the
preferred syntax is CREATE UNIQUE INDEX.
See Also
3-268
Grammar Statements
UPDATE
The UPDATE statement allows you to modify column values in a
database.
Syntax
| [db-name.]table-name [ [ AS ] alias-name ]
| [db-name.]view-name [ [ AS ] alias-name ]
| join-definition
| ( join-definition )
| ( table-subquery )[ AS ] alias-name [ (column-name [ , column-name
]... ) ]
outer-join-definition ::= table-reference outer-join-type JOIN table-reference ON searchcondition
outer-join-type ::= LEFT [ OUTER ] | RIGHT [ OUTER ] | FULL [
OUTER ]
search-condition ::= search-condition AND search-condition
| search-condition OR search-condition
| NOT search-condition
| ( search-condition )
| predicate
db-name ::= user-defined-name
view-name ::= user-defined-name
join-definition ::= table-reference [ join-type ] JOIN table-reference ON searchcondition
3-269
[ OUTER ]
table-subquery ::= query-specification [ [ UNION [ ALL ]
query-specification ]... ]
subquery-expression ::= ( query-specification )
Remarks
Non-correlated Subquery
UPDATE t1 SET t1.c2 = (SELECT SUM(t2.c2) FROM t2 WHERE
t2.c1 = 10)
3-270
Grammar Statements
UPDATE fails. If select returns more than one row, then UPDATE
fails.
An UPDATE statement does not allow the use of join tables in the
statement. Instead, use a correlated subquery in the SET clause as
follows:
UPDATE t1 SET t1.c2 = (SELECT t2.c2 FROM t2 WHERE t2.c1
= t1.c1)
All data types for data created prior to Pervasive.SQL 2000 (legacy
data) report back as nullable. This means that you can UPDATE
NULL into any legacy column type without pseudo-NULL
conversion. The following data types are treated as pseudo-NULL by
default:
Date
Decimal
Money
NumericSA
NumericSTS
Timestamp
Numeric
bytes. If you need to enter data longer than this, see Long Data
on page 3-168 for a useful tip.
3-271
FROM Clause
Some confusion may arise pertaining to the optional FROM clause
and references to the table being updated (referred to as the update
table). If the update table occurs in the FROM clause, then one of
the occurrences is the same instance of the table being updated.
For example, in the statement UPDATE t1 SET c1 = 1 FROM t1,
t2 WHERE t1.c2 = t2.c2, the t1 immediately after UPDATE is the
same instance of table t1 as the t1 after FROM. Therefore, the
statement is identical to UPDATE t1 SET c1 = 1 FROM t2 WHERE
t1.c2 = t2.c2.
If the update table occurs in the FROM clause multiple times, one
occurrence must be identified as the same instance as the update
table. The FROM clause reference that is identified as the same
instance as the update table is the one that does not have a specified
alias.
Therefore, the statement UPDATE t1 SET t1.c1 = 1 FROM t1 a,
t1 b WHERE a.c2 = b.c2 is invalid because both instances of t1 in
the FROM clause contain an alias. The following version is valid:
UPDATE t1 SET t1.c1 = 1 FROM t1, t1 b WHERE t1.c2 = b.c2.
3-272
Grammar Statements
[Pervasive][ODBC Client Interface][LNA][Pervasive]
[ODBC Engine Interface] The table t1 is
ambiguous.
Examples
The following examples updates the record in the faculty table and
sets salary as 95000 for ID 103657107.
UPDATE Faculty SET salary = 95000.00 WHERE ID = 103657107
The following example changes the credit hours for Economics 305
in the course table from 3 to 4.
UPDATE Course SET Credit_Hours = 4 WHERE Name = 'ECO 305'
Subquery Example A
Two tables are created and rows are inserted. The first table, t5, is
updated with a column value from the second table, t6, in each row
where table t5 has the value 2 for column c1. Because there is more
than one row in table t6 containing a value of 3 for column c2, the
3-273
first UPDATE fails because more than one row is returned by the
subquery. This result occurs even though the result value is the same
in both cases. As shown in the second UPDATE, using the
DISTINCT keyword in the subquery eliminates the duplicate results
and allows the statement to succeed.
CREATE
CREATE
INSERT
INSERT
INSERT
INSERT
INSERT
SELECT
Results:
c1
---------1
2
c2
----3
4
Results:
c1
---------1
3
c2
----3
4
Subquery Example B
Two tables are created and a variety of valid syntax examples are
demonstrated. Note the cases where UPDATE fails because the
subquery returns more than one row. Also note that UPDATE
succeeds and NULL is inserted if the subquery returns no rows
(where NULL values are allowed).
CREATE TABLE t1 (c1 INT, c2 INT)
CREATE TABLE t2 (c1 INT, c2 INT)
INSERT INTO t1 VALUES (1, 0)
3-274
Grammar Statements
INSERT
INSERT
INSERT
INSERT
INTO
INTO
INTO
INTO
t1
t1
t2
t2
VALUES
VALUES
VALUES
VALUES
(2,
(3,
(1,
(2,
0)
0)
100)
200)
t1
t1
t1
t1
SET
SET
SET
SET
t1.c2
t1.c2
t1.c2
t1.c2
=
=
=
=
@@IDENTITY
@@ROWCOUNT
(SELECT @@IDENTITY)
(SELECT @@ROWCOUNT)
3-275
See Also
3-276
Grammar Statements
UPDATE (positioned)
The positioned UPDATE statement updates the current row of a
rowset associated with an SQL cursor.
Syntax
Remarks
Examples
3-277
See Also
3-278
Grammar Statements
USER
Remarks
The USER keyword returns the current user name (such as Master)
for each row returned by the SELECT restriction.
Example
The following examples return the user name from the course table.
SELECT USER FROM course
-- returns 145 instances of Master (the table contains 145 rows)
See Also
3-279
WHILE
Use a WHILE statement is used to control flow. It allows code to be
executed repeatedly as long as the WHILE condition is true.
Optionally, you may use the WHILE statement with DO and END
WHILE.
Note You cannot use a mixed syntax for the WHILE statement.
You may use either WHILE with DO and END WHILE, or only
WHILE.
If you are using multiple statements with a WHILE condition,
you must use BEGIN and END to indicate the beginning and
ending of the statement blocks.
Syntax
Remarks
Examples
See Also
3-280
Grammar Statements
COLUMN ]
column-definition
| ADD table-constraint-definition
|
|
|
|
|
alter-option-list2 ::=
as-or-semicolon
::= AS | ;
before-or-after ::=
BEFORE | AFTER
NOT NULL
| UNIQUE
| PRIMARY KEY
| REFERENCES table-name [ (
col-constraint ::=
column-name ) ] [ referential-actions ]
CONSTRAINT
constraint-name ] col-constraint
3-281
::= user-defined-name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expression + expression
expression * expression
expression / expression
expression & expression
expression | expression
expression ^ expression
( expression )
-expression
+expression
~expression
?
literal
scalar-function
{ fn scalar-function }
USER
|
|
|
|
number
{ d 'date-literal' }
{ t 'time-literal' }
{ ts 'timestamp-literal' }
scalar-function :: =
::= | NEXT
]... )
index-segment-definition
3-282
Grammar Statements
index-name
::= user-defined-name
ins-upd-del ::=
query-specification
| table-reference
INNER ] JOIN
CROSS JOIN
table-reference
ON
search-
table-reference
| outer-join-definition
label-name
::= user-defined-name
| number
| { d 'date-literal' }
| { t 'time-literal' }
| { ts 'timestamp-literal' }
order-by-expression ::= expression [
CASE | COLLATE
collation-name ] [
ASC | DESC ]
outer-join-definition ::= table-reference outer-join-type JOIN table-reference
ON search-condition
outer-join-type ::=
[ DEFAULT proc-expr | =
SQLSTATE
3-283
NOT ] BETWEEN
expression
AND
expression
NOT ] IN ( query-specification )
NOT ] IN ( value [ , value ]... )
expression [ NOT ] LIKE value
expression IS [ NOT ] NULL
expression comparison-operator ANY ( query-specification )
expression comparison-operator ALL ( query-specification )
EXISTS ( query-specification )
| expression [
| expression [
|
|
|
|
|
proc-expr
proc-search-condition
proc-stmt
3-284
Grammar Statements
| select-statement-with-into
| select-statement
| SET variable-name = proc-expr
| SIGNAL [ ABORT ] sqlstate-value
| START TRANSACTION [tran-name]
| update-statement
| UPDATE SET column-name = proc-expr [ , column-name = procexpr ]... WHERE CURRENT OF cursor-name
| [ label-name : ] WHILE proc-search-condition DO [ proc-stmt [
; proc-stmt ] ]... END WHILE [ label-name ]
| [ label-name : ]
WHILE
proc-search-condition proc-stmt
| alter-table-statement
| create-index-statement
| create-table-statement
| create-view-statement
| drop-index-statement
| drop-table-statement
| drop-view-statement
| grant-statement
| revoke-statement
| set-statement
procedure-name ::= user-defined-name
public-or-user-group-name ::= PUBLIC | user-group-name
query-specification [ [ UNION [ ALL ] query-specification ]...
[ ORDER BY order-by-expression [ , order-by-expression ]... ] [ FOR
UPDATE ]
query-specification ::= ( query-specification )
NEW [ AS ]
AS ]
correlation-name [
correlation-name [
NEW [ AS ]
OLD [ AS ]
correlation-name ]
3-285
| referential-delete-action [ referential-update-action ]
referential-update-action ::=
ON UPDATE RESTRICT
ON DELETE CASCADE
| ON DELETE RESTRICT
referential-delete-action ::=
release-statement
result
rollback-statement
savepoint-name
::= user-defined-name
| search-condition
|
NOT
OR
AND
search-condition
search-condition
search-condition
| ( search-condition )
| predicate
select-item ::= expression [ [
AS ]
alias-name ] | table-name . *
COUNT (*)
COUNT ( [ DISTINCT | ALL ] expression )
SUM ( [ DISTINCT | ALL ] expression )
AVG ( [ DISTINCT | ALL ] expression )
MIN ( [ DISTINCT | ALL ] expression )
MAX ( [ DISTINCT | ALL ] expression )
set-function ::=
|
|
|
|
|
sqlstate-value
::= 'string'
table-constraint-definition ::= [
constraint
CONSTRAINT
constraint-name ] table-
table-constraint ::=
3-286
Grammar Statements
| FOREIGN KEY ( column-name [ ,
REFERENCES table-name
column-name ] )
| table-constraint-definition
table-expression ::=
ALL
SELECT [ ( column-name [ , column-name ]... ) ]
UPDATE [ ( column-name [ , column-name ]... ) ]
INSERT [ ( column-name [ , column-name ]... ) ]
DELETE
ALTER
REFERENCES
table-privilege ::=
|
|
|
|
|
|
table-reference ::= {
OJ
outer-join-definition }
| [db-name.]table-name [ [
AS ]
alias-name ]
| join-definition
| ( join-definition )
transaction-statement
::= commit-statement
| rollback-statement
| release-statement
trigger-name ::= user-defined-name
user-password ::= user-name [ : ] password
user-group-name ::= user-name | group-name
user-name ::= user-defined-name
value ::= literal |
USER | ?
3-287
VALUES | VALUES (
expression [ ,
::= user-defined-name
SQL Statement
List
Predicate
3-288
AND
Expression
Grammar Statements
|'(' Predicate ')'CompareOperator ::= '=' | '>=' | '>' | '<=' |
'<' | '<>' | '!='
|[ NOT ] IN value-list
Expression
|StringLiteral
|ColumnName
|VariableName
|NULL
|CONVERT '(' Expression ',' DataType ')'
|'-' Expression
|Expression '+' Expression
|Expression '-' Expression
|Expression '*' Expression
|Expression '/' Expression
|Expression '&' Expression
|'~' Expression
|Expression '|' Expression
|Expression '^' Expression
|FunctionName '(' [ ExpressionList ] ')'
|'(' Expression')'
|'{' D StringLiteral '}'
|'{' T StringLiteral '}'
|'{' TS StringLiteral '}'
|@:IDENTITY
|@:ROWCOUNT
|@@IDENTITY
|@@ROWCOUNT
3-289
Global Variables
Pervasive PSQL supports the following global variables:
Global variables are prefaced with two at signs, @@. All global
variables are variables per connection. Each database connection has
its own @@IDENTITY, @@ROWCOUNT, and @@SPID values.
@@IDENTITY
This variable returns the value of the most recently inserted
IDENTITY column value (IDENTITY or SMALLIDENTITY). The
value is a signed integer value. The initial value is NULL.
This variable can only refer to a single column. If the target table
includes more than one IDENTITY column, the value of this
variable refers to the IDENTITY column that is the tables primary
key. If no such column exists, then the value of this variable refers to
the first IDENTITY column in the table.
If the most recent insert was to a table without an IDENTITY
column, then the value of @@IDENTITY is set to NULL.
Examples
SELECT @@IDENTITY
3-290
Global Variables
INSERT INTO t1(c2) VALUES (@@IDENTITY)
Inserts the IDENTITY value of the last row inserted into column C2
of the new row.
UPDATE t1 SET t1.c1 = (SELECT @@IDENTITY) WHERE t1.c1 =
@@IDENTITY + 10
3-291
@@ROWCOUNT
This variable returns the number of rows that were affected by the
most recent operation in the current connection. The value is an
unsigned integer. The initial value is zero.
Examples
SELECT @@ROWCOUNT
Results:
2
The first SELECT generates two rows and shows that the value of
@@ROWCOUNT was 1 when it was used to insert a row. The second
SELECT returns 2 as the value of @@ROWCOUNT, that is, after the
first SELECT returned two rows.
Also see the example for @@IDENTITY.
@@SESSIONID
This variable returns an eight-byte integer value for the Pervasive
PSQL connection. The integer is a combination of a time value and
an incremental counter. This variable can be used to identify
uniquely each Pervasive PSQL connection.
@@SESSIONID requires a connection to the database engine to
return a value. If the connection to the database engine is lost, the
variable cannot return an identifier.
Example
SELECT @@SESSIONID
3-292
Global Variables
@@SPID
This variable (server process identifier) returns the identifier integer
value of the system thread for the Pervasive PSQL connection.
If the connection to the database engine is lost, SPID cannot return
an identifier. Instead, ODBC returns SqlState 08S01.
Example
SELECT @@SPID
3-293
Other Characteristics
This section describes other characteristics of the SQL grammar. It is
divided into the following sections:
Temporary
Files
3-294
Other Characteristics
forward-only cursor
number of bytes in the temporary file is less than 250,000
SELECT statements with ORDER BY, GROUP BY, or
DISTINCT that do not use an index, and that have no BLOB or
CLOB in the ORDER BY, GROUP BY, or DISTINCT, and that
have no BLOB or CLOB in selection list with UNION.
forward-only cursor
number of bytes in the temporary file is greater than 250,000
SELECT statements with ORDER BY, GROUP BY, or
DISTINCT that do not use an index, and that have no BLOB or
CLOB in the ORDER BY, GROUP BY, or DISTINCT, and that
have no BLOB or CLOB in selection list with UNION.
Pervasive PSQL does not create a Btrieve temporary file for each base
table in a static cursor SELECT query. Instead, each base table is
opened by using the MicroKernel to reserve pages in the file as a
static representation of the file. Any change made through a static
cursor cannot be seen by that cursor.
3-295
Working with
Literal Values
String Values
String constants may be expressed in SQL statements by
surrounding the given string of characters with single quotes. Single
quotes contained within the string itself require a preceding single
quote as an escape character.
Examples
Date Values
Date constants may be expressed in SQL statements as a character
string or embedded in a vendor string. The first case is treated as data
type SQL_CHAR and the vendor string representation is treated as a
value of type SQL_DATE. This becomes important when conversions
are attempted.
Pervasive PSQL partially supports extended SQL grammar, as
outlined in this function.
Pervasive PSQL supports the following date literal format: 'YYYYMM-DD'.
Dates may be in the range of year 0 to 9999.
3-296
Other Characteristics
Examples
The next two statements return all the classes whose start date is after
1995-06-05.
SELECT * FROM Class WHERE Start_Date > '1995-06-05'
SELECT * FROM Class WHERE Start_Date > {d '1995-06-05'}
Time Values
Pervasive PSQL supports the following time literal format:
'HH:MM:SS'.
Time constants may be expressed in SQL statements as a character
string or embedded in a vendor string. Character string
representation is treated as a string of type SQL_CHAR and the vendor
string representation as a value of type SQL_TIME.
Pervasive PSQL partially supports extended SQL grammar, as
outlined in this function.
Examples
The following two statements retrieve records from the class table
where the start time for the classes is 14:00:00.
SELECT * FROM Class WHERE Start_time = '14:00:00'
SELECT * FROM Class WHERE Start_time = {t '14:00:00'}
Timestamp Values
Timestamp constants may be expressed in SQL statements as a
character string or embedded in a vendor string. Pervasive PSQL
treats the character string representation as a string of type SQL_CHAR
and the vendor string representation as a value of type SQL_
TIMESTAMP.
Pervasive PSQL partially supports extended ODBC SQL grammar, as
outlined in this function.
Pervasive PSQL supports the following timestamp literal format:
'YYYY-MM-DD HH:MM:SS'
3-297
Examples
The next two statements retrieve records from the Billing table where
the start day and time for the log is 1996-03-28 at 17:40:49.
SELECT * FROM Billing WHERE log = '1996-03-28 17:40:49'
SELECT * FROM Billing WHERE log = {ts '1996-03-28
17:40:49'}
Date Arithmetic
Pervasive PSQL supports adding or subtracting an integer from a
date where the integer is the number of days to add or subtract, and
the date is embedded in a vendor string. (This is equivalent to
executing a convert on the date).
Pervasive PSQL also supports subtracting one date from another to
yield a number of days.
Examples
SELECT * FROM person P, Class C WHERE p.Date_Of_Birth <
' 1973-09-05' AND c.Start_date >{d '1995-05-08'} + 30
Working with
NULL Values
Working with
Binary Data
Consider the following scenario: you insert the literal value '1' into a
BINARY(4) column named c1, in table t1. Next, you enter the
statement, SELECT * FROM t1 WHERE c1='1'.
The engine can retrieve data using the same binary format as was
used to input the data. That is, the SELECT example above works
properly and returns the value, 0x01000000, even though there isnt
a literal match.
3-298
Other Characteristics
Note The engine always adds a zero (0) to the front of odd-digit
binary values that are inserted. For example, if you insert the
value '010', then the value '0x00100000' is stored in the data file.
Currently, Pervasive PSQL does not support suffix 0x to denote
binary constants. Binary constants are a string of hexadecimal
numbers enclosed by single quotation marks.
This behavior is the same as SQL Server.
Creating
Indexes
Closing an
Open Table
3-299
Concurrency
statements where long data columns are included in the selectlist, or SELECT statements with GROUP BY), Pervasive PSQL
may use bookmarks that it assumes are persistent within a
SELECT statement. The situation may arise whereby another
application updates or deletes the row that a bookmark
references.
To avoid this situation, an application may set an exclusive lock
on the table being sorted through a call to SQLSetStmtOption,
with fOption = 1153 and vParam = 1.
Comma as
Decimal
Separator
3-300
Other Characteristics
3-301
Examples
Example A - Server locale uses the comma for decimal
separator
3-302
Other Characteristics
3-303
OEM to ANSI
Support
3-304
chapter
Bitwise Operators
4-1
Bitwise Operators
Overview
Bitwise operators allow you to manipulate the bits of one or more
operands. The following are the types of bitwise operators:
Operator
Meaning
&
bitwise AND
bitwise NOT
bitwise OR
bitwise exclusive OR
4-2
BIT
TINYINT
SMALLINT
INTEGER
BIGINT
UTINYINT
USMALLINT
UINTEGER
UBIGINT
Syntax
Values
Returned
Examples
4-3
Bitwise Operators
4-4
X$File
System table
X$Field
System table
X$Index
System table
Billing
User table
Class
User table
Room
User table
Student
User table
Tuition
User table
Course
User table
Department
User table
Enrolls
User table
Faculty
User table
Person
User table
X$Proc
System table
Syntax
~ expression
Expression is any valid expression containing the integer data type,
which is transformed into a binary number for the bitwise operation.
Values
Returned
The bitwise NOT operator returns the reverse of its single operand
of the integer data type. All 1s are converted to 0s, and all 0s are
converted to 1s. The bitwise NOT can take only numeric values as its
operands.
Examples
complement of 12
The 2's complement of the result number is 13. Therefore, the result
is -13.
Note The tilde (~) cannot be used as part of a user-defined
name.
4-5
Bitwise Operators
Bitwise OR (|)
The bitwise OR operator performs a bitwise logical OR operation
between two operands.
The bitwise OR compares two bits and assigns a value equal to 1 to
the result if the values of either or both the bits are equal to 1. If
neither bit in the input expressions has a value of 1, the bit in the
result is set to 0. The OR operator can take only numeric values as its
operands.
Syntax
expression | expression
Expression is any valid expression containing the integer data type,
which is transformed into a binary number for the bitwise operation.
Values
Returned
Examples
This example first shows how to create a foreign key entry and a
primary key entry in the X$Index table, then how to obtain a list of
foreign and primary key constraints.
Execute of the following statements to create two entries in the
X$Index table (one for a foreign key and one for a primary key).
CREATE TABLE Employee
(
empid
IDENTITY NOT NULL PRIMARY KEY, -- Employee ID
empname VARCHAR(50) NOT NULL, -- Name of employee
supid
INTEGER
NULL -- Id of supervisor
)
ALTER TABLE Employee
ADD CONSTRAINT SupIdMustBeValid
FOREIGN KEY (supid) REFERENCES Employee(empid)
ON DELETE CASCADE
4-6
Bitwise OR (|)
Execute the following to obtain a list of all foreign key and primary
constraints on all tables in the database.
SELECT B.Xf$Name "Table name", C.Xe$Name "Column name",
IF (Xi$Flags & 8192 = 0, 'Primary key', 'Foreign key')
"Key type" from X$Index A, X$File B, X$Field C
WHERE (A.Xi$Flags & (16384 | 8192)) > 0 AND
A.Xi$File = B.Xf$Id AND
A.Xi$Field = C.Xe$Id
empid
supid
Primary key
Foreign key
4-7
Bitwise Operators
Syntax
expression ^ expression
Expression is any valid expression containing the integer data type,
which is transformed into a binary number for the bitwise operation.
Values
Returned
Examples
The result is 4.
The binary representation of 12 (as a shortint) is 0000 0000 0000
0110 and that of 8 is 0000 0000 0000 0100. Performing the exclusive
OR operation on these numbers yields the value 4:
0000 0000 0000 1100 ^ 0000 0000 0000 1000
= 0000 0000 0000 0100 (4)
name.
4-8
Truth Table
Truth Table
The following is the truth table for bitwise operations.
Table 4-1 Truth Table for Bitwise Operations
A
A&B
A|B
A^B
~A
4-9
Bitwise Operators
4-10
chapter
Scalar Functions
5-1
Scalar Functions
String Functions
String functions are used to process and manipulate columns that
consist of text information, such as CHAR or LONGVARCHAR data
types.
The string functions support multiple-byte character strings. (Note,
however, that CASE (string) does not support multiple-byte
character strings. The CASE (string) keyword assumes that the string
data is single-byte ASCII. See CASE (string) on page 3-39.)
Arguments denoted as string can be the name of column, a string
literal, or the result of another scalar function.
Table 5-1 String Functions
5-2
Function
Description
ASCII (string)
BIT_LENGTH (string)
CHAR (code)
CHAR_LENGTH (string)
CHARACTER_LENGTH (string)
Same as CHAR_LENGTH.
LENGTH (string)
String Functions
Description
LTRIM (string)
OCTET_LENGTH (string)
RTRIM (string)
SPACE (count)
5-3
Scalar Functions
In this case, both sides of the predicate are optimized if T1.C1 and
T2.C2 are index columns. The predicate is the complete search
condition following the WHERE keyword. Depending on the size of
the tables involved in the join, the optimizer chooses the appropriate
table to process first.
LTRIM and RIGHT cannot be optimized if they are contained in a
complex expression on either side of the predicate.
Examples
Results of SELECT:
num
---------97
98
65
66
chr
--a
b
A
B
Results of SELECT:
num
-----97
5-4
String Functions
The following example concatenates the first and last names in the
Person table and results in "RooseveltBora".
SELECT CONCAT(First_name, Last_name) FROM Person WHERE
First_name = 'Roosevelt'
The next example changes the case of the first name to lowercase and
then to upper case, and results in "roosevelt", "ROOSEVELT".
SELECT LCASE(First_name),UCASE(First_name) FROM Person
WHERE First_name = 'Roosevelt'
5-5
Scalar Functions
Numeric Functions
Numeric functions are used to process and manipulate columns that
consist of strictly numeric information, such as decimal and integer
values.
Table 5-2 Numeric Functions
5-6
Function
Description
ABS (numeric_exp)
ACOS (float_exp)
ASIN (float_exp)
ATAN (float_exp)
CEILING (numeric_exp)
COS (float_exp)
COT (float_exp)
DEGREES (numeric_exp)
EXP (float_exp)
FLOOR (numeric_exp)
LOG (float_exp)
Numeric Functions
Description
LOG10 (float_exp)
PI ( )
RADIANS (numeric_exp)
RAND (integer_exp)
SIGN (numeric_exp)
SIN (float_exp)
SQRT (float_exp)
TAN (float_exp)
TRUNCATE (numeric_exp,
integer_exp)
5-7
Scalar Functions
Examples
The following example lists the modulus of the number and capacity
columns in a table named Room.
SELECT Number, Capacity, MOD(Number, Capacity) FROM
Room WHERE Building_Name = Faske Building and Type =
Classroom
The following example selects all salaries from a table named Faculty
that are evenly divisible by 100.
SELECT Salary FROM Faculty WHERE MOD(Salary, 100) = 0
5-8
Inserting Time
and Date
Function
Values
If you wish to insert the value of a function into a table, one method
supported by all the time/date functions is to use a SELECT
subquery in your INSERT statement, as shown:
INSERT INTO t1 (c1, c2) SELECT CURRENT_DATE(),
CURRENT_TIME()
Description
CURDATE ( )
Returns the current local date in this format: yyyy-mm-dd. Uses the
local clock time by default. If SET TIME ZONE has been called, then the
value of CURDATE() is determined by calculating UTC time/date from
the system clock and operating system locale setting, then adding the
displacement value specified with SET TIME ZONE.
CURRENT_DATE ( )
CURTIME ( )
Returns the current local time in this format: hh:mm:ss. Uses the local
clock time by default. If SET TIME ZONE has been called, then the value
of CURTIME() is determined by calculating UTC time/date from the
system clock and operating system locale setting, then adding the
displacement value specified with SET TIME ZONE.
CURRENT_TIME ( )
CURRENT_TIMESTAMP ( )
Returns the current UTC date and time as a timestamp value in this
format:
yyyy-mm-dd hh:mm:ss.sssssss
5-9
Scalar Functions
Description
5-10
Description
Returns an integer for the difference between the two dates. The integer
is the number of date and time boundaries crossed between the two
dates.
For example, suppose that table mytest has two columns,col1 and col2,
both of which are DATETIME. The value in col1 is 2000-01-01
11:11:11.234 and the value in col2 is 2004-09-11 10:10:10.211. The
following SELECT statement returns 56, because that is the difference
in months between col1 and col2: SELECT DATEDIFF(month, col1,
col2) as Month_Difference FROM mytest.
Datepart specifies the part of the date on which to calculate the
difference, and must be one of the following values.
year
quarter
month
day
dayofyear
week
hour
minute
second
millisecond
Start specifies the beginning date for the difference calculation. Start is
an expression that returns a DATETIME value or a Unicode character
string in a DATE format.
End specifies the ending date for the difference calculation. End is an
expression that returns a DATETIME value or a Unicode character string
in a DATE format.
Start is subtracted from end. An error is returned if the return value is
outside of the range for integer values. See Data Type Ranges on page
A-5.
5-11
Scalar Functions
Description
5-12
Description
DAYNAME (date_exp)
DAYOFMONTH (date_exp)
DAYOFYEAR (date_exp)
Returns the day of the year based on the year field in date_exp as an
integer value in the range of 1-366.
EXTRACT (extract_field,
extract_source)
HOUR (time_exp)
MINUTE (time_exp)
MONTH (date_exp)
MONTHNAME (date_exp)
5-13
Scalar Functions
Description
NOW ( )
Returns the current local date and time as a timestamp value in this
format:
yyyy-mm-dd hh:mm:ss.sssssss
Uses the local clock time by default. If SET TIME ZONE has been called,
then the value of NOW() is determined by calculating UTC time/date
from the system clock and operating system locale setting, then adding
the displacement value specified with SET TIME ZONE.
QUARTER (date_exp)
SECOND (time_exp)
TIMESTAMPADD (interval,
integer_exp, timestamp_exp)
TIMESTAMPDIFF (interval,
timestamp_exp1,
timestamp_exp2)
WEEK (date_exp)
Returns the week of the year based on the week field in date_exp as an
integer in the range of 1 to 53. Date_exp can be a DATE, TIMESTAMP
literal, or a column containing DATE, TIMESTAMP, or DATETIME data.
YEAR (date_exp)
Returns the year as an integer value. The range depends on the data
source. Date_exp can be a DATE, TIMESTAMP literal, or a column
containing DATE, TIMESTAMP, or DATETIME data.
Examples
5-14
The following example shows how to insert values from time or date
functions. Some functions, such as CURDATE(), you can use
directly in an INSERT statement. Other functions, however, are not
supported in this manner. The method with the widest support is to
use INSERT with SELECT. In the example below, the UTC time value
returned by CURRENT_TIME() is inserted into table T1:
INSERT INTO T1 (C1) SELECT CURRENT_TIME()
The following is a complex example that uses month, day, year, hour
and minute.
SELECT Name, Section, MONTH(Start_Date),
DAY(Start_Date), YEAR(Start_Date), HOUR(Start_Time),
MINUTE(Start_Time) FROM Class
The next example gives the day of the month and day of the week of
the start date of class from the class table.
SELECT DAYOFMONTH(Start_date), DAYOFWEEK(Start_date)
FROM Class
SELECT * FROM person WHERE YEAR(Date_Of_Birth) < 1970
5-15
Scalar Functions
System Functions
System functions provide information at a system level.
Table 5-4 System Functions
Examples
Function
Description
DATABASE ( )
NEWID ( )
USER ( )
The following examples show how to obtain the name of the current
user and database:
SELECT USER()
SELECT DATABASE()
5-16
Logical Functions
Logical Functions
Logical functions are used to manipulate data based on certain
conditions.
Table 5-5 Logical Functions
Function
Description
COALESCE (expression1,
expression2 [, ... ] )
Examples
IF (predicate, expression1,
expression2)
NULL ( )
5-17
Scalar Functions
The system scalar function NULL allows you to set a column as null
values. The syntax is:
NULL()
For example, the following SQL statement inserts a row in the Room
table with a NULL value for Capacity:
INSERT INTO Room VALUES (Young Building, 222, NULL(),
Lab)
5-18
Logical Functions
INSERT INTO Demo VALUES ('xyz')
Since the second row contains the NULL value, 'foo' is substituted
in its place.
SELECT IFNULL(col1, 'foo') FROM Demo
The first row contains abc, which matches the second argument of
the following NULLIF call.
SELECT NULLIF(col1, 'abc') FROM Demo
5-19
Scalar Functions
Conversion Functions
The conversion functions convert an expression to a data type. The
CONVERT function can convert data only to an ODBC data type.
Note that more than one Pervasive PSQL data type may be mapped
to the same ODBC type. For example, DECIMAL, CURRENCY, and
BIGINT are all mapped to the ODBC data type SQL_DECIMAL.
The CAST function converts an expression to a Pervasive PSQL
relational data type (provided that the expression can be converted
to the data type). The CAST function can convert binary zeros in a
string. For example, CAST(c1 AS BINARY(10)), where c1 is a
character column that contains binary zeros (NULLs).
You cannot CAST or CONVERT user-defined data types.
If both the input and the output are character strings, the output
from CAST or CONVERT has the same collation as the input string.
5-20
Conversion Functions
Description
Examples
5-21
Scalar Functions
If the current date were January 1, 2004, the SELECT returns 200401-01.
5-22
Conversion Functions
5-23
Scalar Functions
5-24
chapter
6-1
prefix, do not create any stored procedures with the psp_ prefix.
Any user-created stored procedure with the same name as that of
a system stored procedure will never be executed.
The following table lists the system stored procedures currently
supported.
Table 6-1 Pervasive PSQL System Stored Procedures
psp_columns
psp_column_attributes
psp_column_rights
psp_fkeys
psp_groups
psp_help_sp
psp_help_trigger
psp_help_udf
psp_help_view
psp_indexes
psp_pkeys
psp_procedure_rights
psp_rename
psp_stored_procedures
psp_tables
psp_table_rights
psp_triggers
psp_udfs
psp_users
psp_view_rights
psp_views
Unless otherwise noted, the code examples for the system stored
procedures refer to the Demodata sample database provided with
Pervasive PSQL or to Pervasive PSQL system tables. (For default
locations of Pervasive PSQL files, see Where are the Pervasive PSQL
v10 files installed? on page 7-2 in Getting Started With Pervasive
PSQL.)
If you execute a system stored procedure in the context of a database
(for example, A) and try to obtain information from a secured
database (for example, B), an error message appears. You cannot
obtain information from a secured database from any other
database.
6-2
psp_columns
Arguments
Table 6-2 psp_columns Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
column_name
VARCHAR(255)
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
Name of the table owner. Table owner is reserved for future use.
It currently returns empty (NULL).
TABLE_NAME
VARCHAR(255)
COLUMN_NAME
VARCHAR(255)
DATA_TYPE
SMALLINT
ODBC data type code of the column. See Pervasive PSQL Data
Types and Equivalent ODBC Data Types on page A-2.
TYPE_NAME
VARCHAR (32)
PRECISION
INTEGER
6-3
Data Type
Description
LENGTH
INTEGER
SCALE
SMALLINT
The scale of the column if the data type is Decimal, Numeric, and
so forth.
RADIX
SMALLINT
NULLABLE
SMALLINT
Specifies nullability:
1 - NULL allowed
0 - NULL not allowed
REMARKS
VARCHAR(255)
Remarks field
Examples
create table tx (c_binary BINARY(10),
c_char CHAR(10),
c_tinyint TINYINT,
c_smallint SMALLINT,
c_int INT,
c_bigint BIGINT,
c_utinyint UTINYINT)
call psp_columns(, 'tx',)
6-4
Result Set
Table_
qualifier
Table_
owner
Table_
name
Column
_name
Data_
type
Type_
name
'demodata'
Null
tx
C_binary
-2
Binary
10
10
Null
Null
Null
'demodata'
Null
tx
C_char
-1
Char
10
10
Null
Null
Null
'demodata'
Null
tx
C_tinyint
-6
Tinyint
Null
10
Null
.....
Legend: P = Precision; L = Length; S = Scale; R = Radix; N = Nullable; R = Remarks
Result Set
Table_
qualifier
Table_
owner
Table_
name
Column
_name
Data_
type
Type_
name
'wsrde'
Null
tx
C_binary
-2
Binary
10
10
Null
Null
Null
'wsrde'
Null
tx
C_char
-1
Char
10
10
Null
Null
Null
'wsrde'
Null
tx
C_tinyint
-6
Tinyint
Null
10
Null
.....
Legend: P = Precision; L = Length; S = Scale; R = Radix; N = Nullable; R = Remarks
Result Set
Table_
qualifier
Table_
owner
Table_
name
Column
_name
Data_
type
Type_
name
'wsrde'
Null
tx
C_binary
-2
Binary
10
10
Null
Null
Null
6-5
Error Conditions
psp_column_
attributes
Condition
Error Message
database_qualifier is an undefined
database
table_name is null
Arguments
Table 6-4 psp_column_attributes Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
table_name
VARCHAR(255)
column_name
VARCHAR(255)
6-6
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
TABLE_NAME
VARCHAR(255)
COLUMN_NAME
VARCHAR(255)
ATTRIB_TYPE
CHAR(10)
ATTRIB_SIZE
USMALLINT
ATTRIB_VALUE
LONGVARCHAR
Examples
create table tx (c_binary binary (10) default 01,
c_char char (11) default 'thisisatest',
c_tinyint TINYINT,
c_SMALLINT SMALLINT,
c_int INT,
c_bigint BIGINT,
c_utinyint uTINYINT)
call psp_column_attributes(, , )
Result Set
Table_
qualifier
Table_owner
Table_name
Column_name
Attrib_Type
Attrib_Size
Attrib_Value
'demodata'
Null
tx
C_binary
Default
01
'demodata'
Null
tx
C_char
Default
11
'Thisisatest'
6-7
Result Set
Table_
qualifier
Table_owner
Table_name
Column_name
Attrib_Type
Attrib_Size
Attrib_Value
'demodata'
Null
tx
C_binary
Default
01
Error Conditions
psp_column_
rights
Condition
Error Message
database_qualifier is an undefined
database
table_name is null
Syntax
call psp_column_rights(['database_qualifier'], 'table_
name', ['column_name'], ['user_name'])
6-8
Arguments
Table 6-6 psp_column_rights Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
All tables
column_name
VARCHAR(255)
user_name
VARCHAR(255)
Current user
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
USER_NAME
(GRANTEE)
VARCHAR(255)
TABLE_NAME
VARCHAR(255)
COLUMN_NAME
VARCHAR(255)
Name of the column for which the different rights have been
granted
RIGHTS
VARCHAR(12)
Examples
Assume that the following permissions exist for the DEMODATA
sample database:
6-9
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Column_name
Rights
Demodata
Null
John
Dept
Name
SELECT
Demodata
Null
John
Dept
Building_name
SELECT
Demodata
Null
John
Dept
Building_name
INSERT
Demodata
Null
Mary
Dept
Name
UPDATE
Note The Master user does not have explicit column rights
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Column_name
Rights
Demodata
Null
John
Dept
Building_name
INSERT
Demodata
Null
John
Dept
Building_name
SELECT
Demodata
Null
John
Dept
Name
SELECT
6-10
Note If a user has been granted rights at the table level (for
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Column_name
Rights
Demodata
Null
John
Dept
Name
SELECT
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Column_name
Rights
Demodata
Null
Mary
Dept
Name
UPDATE
6-11
Error Conditions
psp_fkeys
Condition
Error Message
table_name is null
Returns the foreign key information for the specified table in the
current database.
Syntax
call psp_fkeys(['table_qualifier'], 'pkey_table_name',
['fkey_table_name'])
Arguments
Table 6-8 psp_fkeys Arguments
Parameter
Type
Default Value
Description
table_qualifier
VARCHAR(20)
Current database
pkey_table_name
VARCHAR(255)
fkey_table_name
VARCHAR(255)
6-12
Data Type
Description
PKTABLE_
QUALIFIER
VARCHAR (20)
PKTABLE_OWNER
VARCHAR (20)
PKTABLE_NAME
VARCHAR(255)
PKCOLUMN_NAME
VARCHAR(255)
KEY_SEQ
USMALLINT
FKTABLE_
QUALIFIER
VARCHAR (20)
FKTABLE_OWNER
VARCHAR (20)
FKTABLE_NAME
VARCHAR(255)
FKCOLUMN_NAME
VARCHAR(255)
UPDATE_RULE
Utinyint
Update Rule
DELETE_RULE
Utinyint
Delete Rule
PK_NAME
VARCHAR(255)
FK_NAME
VARCHAR(255)
Examples
CREATE TABLE Employee
(
Id INTEGER NOT NULL,
Name VARCHAR(50) NOT NULL,
SupId INTEGER NOT NULL
)
ALTER TABLE Employee
ADD CONSTRAINT EmpPkey
PRIMARY KEY(Id)
ALTER TABLE Employee
ADD CONSTRAINT ForgnKey
FOREIGN KEY(SupId) REFERENCES
6-13
Result Set
PkQ
PkO
PkT
PkCol
Seq
FkQ
FkO
FkT
FkCol
UR
DR
PK
FK
Demo
data
Null
Empl
oyee
Id
Demo
data
Null
Employ
ee
Supid
Emp
Pkey
Forgn
Key
Legend: PkQ = Pkey_ table_ qualifier; PkO = Pkey_table_owner; PkT = Pktable_ name; PkCol = Pk_ column_
name; Seq = Key_seq; FkQ = Fktable_qualifier; FkO = Fktable_owner; FkT = Fktable_name; FkCol =
Fkcolumn_name; UR = Update_rule; DR = Delete_rule; Pk = Pk_ name; FK = Fk_ name
Error Conditions
psp_groups
Condition
Error Message
pKey_table_name is null
6-14
Arguments
Table 6-10 psp_groups Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
group_name
VARCHAR(255)
Data Type
Description
DATABASE_
QUALIFIER
VARCHAR (20)
GROUP_ID
USMALLINT
Group Id
GROUP_NAME
VARCHAR (255)
Examples
Assume that the Demodata sample database has two groups defined:
DevGrp1 and DevGrp2.
call psp_groups(,)
Result Set
Database_qualifier
Group_Id
Group_Name
Demodata
PUBLIC
Demodata
DevGrp1
Demodata
DevGrp2
6-15
Result Set
Database_qualifier
Group_Id
Group_Name
Demodata
DevGrp1
Demodata
DevGrp2
Error Conditions
psp_help_sp
Condition
Error Message
Arguments
Table 6-12 psp_help_sp - Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
procedure_name
CHAR(255)
6-16
Data Type
Description
DATABASE_QUALIFIER
VARCHAR (20)
SP_TEXT
LONGVARCHAR
Examples
Assume that the DEMODATA sample database contains the
following stored procedure saved as Myproc.
Create procedure Myproc(:a integer, OUT :b integer) as
Begin
Set :a = :a + 10;
Set :b = :a;
End
Result Set
Database_Qualifier
Demodata
SP_TEXT
returns (name
6-17
Result Set
Database_Qualifier
wsrde
SP_TEXT
Error Conditions
psp_help_
trigger
Condition
Error Message
procedure_name is null
6-18
Arguments
Table 6-14 psp_help_trigger - Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
trigger_name
VARCHAR(255)
Data Type
Description
DATABASE_
QUALIFIER
VARCHAR (20)
TRIGGER_TEXT
LONGVARCHAR
Examples
The following statement prints the definition of the 'MyInsert'
trigger:
CREATE TABLE A
(
col1 INTEGER,
col2 CHAR(255)
)
CREATE TABLE B
(
col1 INTEGER,
col2 CHAR(255)
)
CREATE TRIGGER MyInsert
AFTER INSERT ON A
FOR EACH ROW
INSERT INTO B VALUES
(NEW.col1, NEW.col2)
6-19
call psp_help_trigger(,'MyIns%')
Result Set
Database_Qualifier
Demodata
TRIGGER_TEXT
Error Conditions
psp_help_udf
Condition
Error Message
trigger_name is null
Arguments
Table 6-16 psp_help_udf - Arguments
Parameter
Type
Default Value
Description
Database_qual
VARCHAR(20)
Current database
udf_name
VARCHAR(255)
6-20
Data Type
Description
DATABASE_
QUALIFIER
VARCHAR (20)
UDF_TEXT
LONGVARCHAR
Examples
call psp_help_udf(, 'Myfunction')
Result Set
Database_Qualifier
Demodata
UDF_TEXT
6-21
Result Set
Database_Qualifier
wsrde
UDF_TEXT
Error Conditions
psp_help_view
Condition
Error Message
udf_name is null
Returns the definition text of a view, from the current database or the
specified database.
Syntax
call psp_help_view(['database_qualifier'], 'view_name')
6-22
Arguments
Table 6-18 psp_help_view - Arguments
Parameter
Type
Default Value
Description
Database_qual
VARCHAR(20)
Current database
view_name
VARCHAR(255)
Data Type
Description
DATABASE_QUALIFIER
VARCHAR (20)
VIEW_TEXT
LONGVARCHAR
Example
Assume that the following view exists for the DEMODATA sample
database:
CREATE VIEW vw_Person (lastn,firstn,phone) AS
SELECT Last_Name, First_Name, Phone
FROM Person
The following statement returns the definition text for view vw_
Person in the DEMODATA database.
call psp_help_view(,'vw_Person')
or
call psp_help_view(,'vw_%')
6-23
Result Set
Database_Qualifier
Demodata
VIEW_TEXT
Error Conditions
psp_indexes
Condition
Error Message
view_name is null
Returns the list of indexes defined for the specified table. For each
index, it also lists the index properties as persisted in the X$Index
table.
Syntax
call psp_indexes(['table_qualifier'], ['table_name'])
Arguments
Table 6-20 psp_indexes Arguments
Parameter
Type
Default Value
Description
table_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
6-24
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
TABLE_NAME
VARCHAR(255)
INDEX_NAME
VARCHAR(255)
INDEX_TYPE
VARCHAR (20)
COLUMN_NAME
VARCHAR(255)
ORDINAL_POSITION
USMALLINT
DUPLICATES_ALLOWED
CHAR(3)
UPDATABLE
CHAR(3)
CASE_SENSITIVE
CHAR(3)
ASC_DESC
CHAR(1)
D, Descending
A, Ascending
NAMED_INDEX
CHAR(3)
Example
call psp_indexes(,)
6-25
Result Set
Qual
TO
TN
IN
IT
CN
Opos
Dup
Up
Case
A/D
NI
Demo
data
Null
Billing
Student_
Trans
Normal
Index
Student_ID
No
Yes
No
Yes
Demo
data
Null
Billing
Student_
Trans
Normal
Index
Transaction
_Number
No
Yes
No
Yes
Demo
data
Null
Billing
Student_
Trans
Normal
Index
Log
No
Yes
No
Yes
.....
Legend: Qual = Table_ qualifier; TO = Table_owner; TN = Table_name; IN = Index_name; IT = Index_type; CN
= Column_name; Opos = Ordinal_position; Dup = Duplicates_allowed; UP = Updatable; Case = Case_
sensitive; A/D = Asc_desc; NI = Named_index
Result Set
Qual
TO
TN
IN
IT
CN
Opos
Dup
Up
Case
A/D
NI
Demo
data
Null
Dept
Building_Room
Normal
Index
Building
_Name
Yes
Yes
Yes
Yes
Demo
data
Null
Dept
Building_Room
Normal
Index
Room_
Number
Yes
Yes
No
Yes
Demo
data
Null
Dept
Dept_Head
Normal
Index
Head_
Of_Dept
No
Yes
No
Yes
Demo
data
Null
Dept
Dept_Name
Normal
Index
Name
No
Yes
Yes
Yes
6-26
Error Conditions
psp_pkeys
Condition
Error Message
Returns the primary key information for the specified table, from the
current database or the database specified.
Syntax
call psp_pkeys(['pkey_table_qualifier']'table_name')
Arguments
Table 6-22 psp_pkeys Arguments
Parameter
Type
Default Value
Description
pkey_table_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
TABLE_NAME
VARCHAR(255)
COLUMN_NAME
VARCHAR(255)
COLUMN_SEQ
USMALLINT
PK_NAME
VARCHAR(255)
6-27
Examples
The following statement returns the information about the primary
key defined on the 'pkeytest1' table:
CREATE TABLE pkeytest1
(
col1 int NOT NULL,
col2 int NOT NULL,
col3 VARCHAR(20) NOT NULL,
PRIMARY KEY(col1, col2),
UNIQUE(col3)
)
call psp_pkeys(,'pkeytest1')
Result Set
Table_
qualifier
Table_
owner
Table_name
Column_
name
Column_
Seq
PK_name
'demodata'
Null
Pkeytest1
Col1
PK_col1
'demodata'
Null
Pkeytest1
Col2
PK_col1
Error Conditions
psp_
procedure_
rights
Condition
Error Message
table_name is null
6-28
Arguments
Table 6-24 psp_procedure_rights Arguments
Parameter
Type
Default Value
Description
database_qualifier
VARCHAR(20)
Current database
procedure_name
VARCHAR(255)
user_name
VARCHAR(255)
Current user
Data Type
Description
PROCEDURE_QUALIFIER
VARCHAR (20)
PROCEDURE_OWNER
VARCHAR (20)
USER_NAME (GRANTEE)
VARCHAR(255)
PROCEDURE_NAME
VARCHAR(255)
RIGHTS
VARCHAR(12)
Examples
Assume that the following permissions exist for the DEMODATA
sample database:
GRANT
GRANT
GRANT
GRANT
GRANT
GRANT
6-29
Result Set
Procedure_Qualifier
Procedure_owner
User_name
Procedure_name
Rights
Demodata
Null
John
Dept1_Proc
ALTER
Demodata
Null
John
Dept1_Proc
EXECUTE
Result Set
Procedure_Qualifier
Procedure_owner
User_name
Procedure_name
Rights
Demodata
Null
Mary
MyProc
ALTER
Demodata
Null
Mary
Proc2
ALTER
Demodata
Null
Mary
Proc2
EXECUTE
Error Conditions
6-30
Condition
Error Message
psp_rename
Arguments
Table 6-26 psp_rename Arguments
Parameter
Type
Description
object_name
VARCHAR(776)
new_name
VARCHAR(776)
A user-defined name for the object. The name must conform to the
naming conventions for the type of object. See Naming Conventions
on page 12-6 in Pervasive PSQL Programmer's Guide, which is part
of the Pervasive PSQL Software Developers Kit (SDK).
object_type
VARCHAR(13)
Example
The following statement renames stored procedure checkstatus to
eligibility in the current database.
call psp_rename('checkstatus', 'eligibility',
'PROCEDURE')
6-31
Error Conditions
All errors returned from psp_rename use status code -5099. See 5099: error condition pertaining to psp_rename on page 1-45 in
Status Codes and Messages.
psp_stored_
procedures
Arguments
Table 6-27 psp_stored_procedures Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
procedure_name
VARCHAR(255)
procedure_type
VARCHAR(5)
6-32
Data Type
Description
PROCEDURE_QUALIFIER
VARCHAR (20)
PROCEDURE _OWNER
VARCHAR (20)
PROCEDURE _NAME
VARCHAR(255)
PROCEDURE_TYPE
VARCHAR(25)
NUM_INPUT_PARAMS
INT
NUM_OUTPUT_PARAMS
INT
NUM_RESULT_SETS
INT
REMARKS
VARCHAR(255)
Remarks
TRUSTEE
INTEGER
Examples
Assume that the current database, "mydbase," contains two stored
procedures: "myproc1" and "myproc2." The following statement lists
the information about them.
Call psp_stored_procedures(, ,)
6-33
Result Set
Qualifier1
Owner1
Name1
Type1
Num_
input_
params
Num_
output_
params
Num_
result
_sets
Remarks
mydbase
Null
Myproc1
Stored
Procedure
Null
Null
Null
Null
mydbase
Null
Myproc2
Stored
Procedure
Null
Null
Null
Null
Trustee
1The
complete column name includes procedure_ prepended to this name: Procedure_qualifier, procedure_
owner, and so forth.
Result Set
Qualifier1
Owner1
Name1
Type1
Num_
input_
params
Num_
output_
params
Num_
result
_sets
Remarks
pervasive
systdb
Null
psp_udfs
Stored
Procedure
Null
Null
Null
Null
pervasive
systdb
Null
psp_users
Stored
Procedure
Null
Null
Null
Null
Trustee
1
The complete column name includes procedure_ prepended to this name: Procedure_qualifier, procedure_
owner, and so forth.
6-34
Error Conditions
psp_tables
Condition
Error Message
Arguments
Table 6-29 psp_tables Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
table_type
VARCHAR(20)
6-35
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
TABLE_NAME
VARCHAR(255)
TABLE_TYPE
VARCHAR (15)
REMARKS
VARCHAR(255)
Remarks
FILE_LOCATION
VARCHAR(255)
Examples
call psp_tables(,,)
Result Set
Table_Qualifier
Table_owner
Table_name
Table_Type
Remarks
File_
location
Demodata
Null
X$file
System table
Null
File.ddf
Demodata
Null
X$field
System table
Null
Field.ddf
Demodata
Null
X$Attrib
System table
Null
Attrib.ddf
Demodata
Null
Billing
User table
Null
Billing.mkd
.....
6-36
Result Set
Table_Qualifier
Table_owner
Table_name
Table_Type
Remarks
File_
location
Demodata
Null
Class
User table
Null
class.mkd
Demodata
Null
Billing
User table
Null
Billing.mkd
.....
Result Set
Table_Qualifier
Table_owner
Table_name
Table_Type
Remarks
File_
location
Demodata
Null
X$file
System table
Null
File.ddf
Demodata
Null
X$field
System table
Null
Field.ddf
Demodata
Null
X$Attrib
System table
Null
Attrib.ddf
.....
Error Conditions
Condition
Error Message
6-37
psp_table_
rights
Returns the list of table rights and corresponding information for the
specified table, from the current database or the specified database.
Syntax
call psp_table_rights(['database_qualifier'], ['table_
name'], ['user_name'])
Arguments
Table 6-31 psp_table_rights Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
All tables
user_name
VARCHAR(255)
Current user
6-38
Data Type
Description
TABLE_QUALIFIER
VARCHAR (20)
TABLE_OWNER
VARCHAR (20)
USER_NAME
(GRANTEE)
VARCHAR(255)
TABLE_NAME
VARCHAR(255)
RIGHTS
VARCHAR(12)
Examples
Assume that the following permissions exist for the DEMODATA
sample database.
GRANT
GRANT
GRANT
GRANT
GRANT
6-39
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Rights
Demodata
Null
John
Dept
ALTER
Demodata
Null
John
Dept
DELETE
Demodata
Null
John
Dept
SELECT
Result Set
Table_Qualifier
Table_owner
User_name
Table_name
Rights
Demodata
Null
Mary
Class
SELECT
Demodata
Null
Mary
Class
ALTER
Error Conditions
psp_triggers
Condition
Error Message
6-40
Arguments
Table 6-33 psp_triggers Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
table_name
VARCHAR(255)
All tables
Data Type
Description
TRIGGER_
QUALIFIER
VARCHAR (20)
TRIGGER_OWNER
VARCHAR (20)
TABLE_NAME
VARCHAR(255)
TRIGGER_NAME
VARCHAR(255)
ISUPDATE
UTINYINT
ISDELETE
UTINYINT
ISINSERT
UTINYINT
ISAFTER
UTINYINT
ISBEFORE
UTINYINT
REMARKS
VARCHAR(255)
Remarks
Examples
Assume that the current database is "mydbase." The following
statement returns the list of triggers defined in the database:
CREATE TABLE A
(
col1 INTEGER,
col2 CHAR(255)
6-41
Result Set
Trigger_
qualifier
Trigger
_owner
Table_
name
Trigger
_name
isupdate
isdelete
isinsert
isafter
isbefore
Remarks
mydbase
Null
Insert
Null
Error Conditions
psp_udfs
Condition
Error Message
6-42
Arguments
Table 6-35 psp_udfs Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
udf_name
VARCHAR(255)
Data Type
Description
UDF_QUALIFIER
VARCHAR (20)
UDF_OWNER
VARCHAR (20)
UDF _NAME
VARCHAR(255)
UDF_TYPE
VARCHAR(25)
NUM_INPUT_
PARAMS
INT
NUM_OUTPUT_
PARAMS
INT
NUM_RESULT_
SETS
INT
REMARKS
VARCHAR(255)
Remarks
Examples
Assume that the current database, "mydbase," has two user-defined
functions: "calcinterest" and "factorial."
call psp_udfs(, )
6-43
Result Set
UDF_
qualifier
UDF_
owner
UDF_name
Udf_type
Num_ input_
params
Num_ output_
params
Num_
result_sets
Remarks
mydbase
Null
CalcInterest
Null
Null
mydbase
Null
Factorial
Null
Null
Error Conditions
psp_users
Condition
Error Message
Returns the list of users and the corresponding information from the
current database or the specified database.
Syntax
call psp_users(['database_qualifier'], ['group_name'],
['user_name'])
Arguments
Table 6-37 psp_users Arguments
Parameter
Type
Default Value
Description
database_qualifier
VARCHAR(20)
Current database
group_name
VARCHAR(255)
user_name
VARCHAR(255)
6-44
Data Type
Description
DATABASE_QUALIFIER
VARCHAR(20)
GROUP_ID
USMALLINT
GROUP_NAME
VARCHAR(255)
USER_ID
USMALLINT
ID of the user
USER_NAME
VARCHAR(255)
Examples
Assume that current database, "mydbase," has users "John," "Mary,"
and "Michael," and groups "DevGrp" and "DevGrp1."
call psp_users(, ,
Result Set
Database_qualifier
Group_Id
Group_Name
User_Id
User_Name
Demodata
DevGrp
John
Demodata
DevGrp1
Mary
Demodata
DevGrp
Michael
6-45
Result Set
Database_qualifier
Group_Id
Group_Name
User_Id
User_Name
Demodata
DevGrp
John
Demodata
DevGrp
Michael
Error Conditions
psp_view_
rights
Condition
Error Message
user_name is null
Arguments
Table 6-39 psp_view_rights Arguments
Parameter
Type
Default Value
Description
database_qualifier
VARCHAR(20)
Current database
view_name
VARCHAR(255)
user_name
VARCHAR(255)
6-46
Data Type
Description
VIEW_QUALIFIER
VARCHAR (20)
VIEW_OWNER
VARCHAR (20)
USER_NAME (GRANTEE)
VARCHAR(255)
VIEW_NAME
VARCHAR(255)
RIGHTS
VARCHAR(12)
Examples
Assume that the following permissions exist for the DEMODATA
sample database:
GRANT
GRANT
GRANT
GRANT
GRANT
GRANT
Result Set
View_Qualifier
View_owner
User_name
View_name
Rights
Demodata
Null
John
vw_Dept
ALTER
Demodata
Null
John
vw_Dept
DELETE
Demodata
Null
John
vw_Dept
SELECT
6-47
Result Set
View_Qualifier
View_owner
User_name
View_name
Rights
Demodata
Null
Mary
vw_Class
ALTER
Demodata
Null
Mary
vw_Class
SELECT
Result Set
View_Qualifier
View_owner
User_name
View_name
Rights
Demodata
Null
Mary
vw_Class
ALTER
Demodata
Null
Mary
vw_Class
SELECT
Error Conditions
6-48
Condition
Error Message
psp_views
Arguments
Table 6-41 psp_views Arguments
Parameter
Type
Default Value
Description
Database_qualifier
VARCHAR(20)
Current database
view_name
VARCHAR(255)
Data Type
Description
VIEW_QUALIFIER
VARCHAR (20)
VIEW_OWNER
VARCHAR (20)
VIEW_NAME
VARCHAR(255)
REMARKS
VARCHAR(255)
Remarks
TRUSTEE
INTEGER
For V2 metadata, returns 0 for a trusted view and -1 for a nontrusted view. The TRUSTEE column is empty for V1 metadata.
Examples
Assume that the following view exists for a V2 metadata database
named DEMODATA2.
CREATE VIEW vw_Person (lastn,firstn,phone) WITH EXECUTE
AS Master AS
SELECT Last_Name, First_Name,Phone FROM Person;
6-49
Result Set
View_Qualifier
View_Owner
View_Name
Remarks
Trustee
Demodata
Null
Vw_Person
Null
The following statement prints the view information for the vw_
Person view in the DEMODATA database.
call psp_views('demodata', 'vw_P%')
Result Set
View_Qualifier
View_Owner
View_Name
Remarks
Demodata
Null
Vw_Person
Null
Trustee
Error Conditions
6-50
Condition
Error Message
6-51
6-52
chapter
Performance Reference
7-1
Performance Reference
Restriction Analysis
This section explains one method that the database engine uses to
analyze and optimize on a Restriction. For definitions of the
technical terms used in this chapter, see Terminology on page 7-18.
Modified CNF
Conversion
Restrictions
that Cannot be
Converted
Conditions
Under Which
Conversion is
Avoided
7-2
There are some cases in which the database engine may be capable of
converting a restriction into modified CNF but will not do so. The
database engine chooses not to convert a restriction to modified
CNF in cases where it has determined that the restriction is more
likely to benefit from optimizations that can be applied to its original
form than from optimizations that could be applied after modified
CNF conversion.
Restriction Analysis
7-3
Performance Reference
Restriction Optimization
This section provides a detailed description of the primary
techniques employed by the database engine to make use of
expressions in a restriction for optimization purposes. The types of
optimizations performed by the database engine are described below
in order from the simplest to the most complex.
A clear understanding of optimization techniques used by the
database engine may aid you in structuring queries to achieve
optimal performance from the database engine. In addition, by
understanding how the database engine uses indexes to optimize
queries, you can determine how to construct indexes that provide the
best performance for a given set of typical uses.
For the sake of simplicity, the descriptions below initially address
expressions that reference columns from only a single table.
Optimizations making use of join conditions, in which predicates
compare columns from two different tables, are described following
the single table optimizations.
For definitions of the technical terms used in this chapter, see
Terminology on page 7-18.
Single
Predicate
Optimization
7-4
Restriction Optimization
Closed Range
Optimization
Modified
Disjunct
Optimization
Conjunct
Optimization
7-5
Performance Reference
For example, suppose an index exists with the first three segments on
columns c1, c2 and c3, in that order. The following conjunct
assignments can be used for optimization:
c1 = 1 AND c2 = 1 AND c3 = 1
c1 = 1 AND c2 = 1 AND c3 >= 1
c1 = 1 AND c2 > 1
The order of the predicates does not matter. For example, the
following conjunct can be used for optimization:
c2 = 1 AND c3 = 1 AND c1 = 1
Disjunctive
Normal Form
Optimization
The database engine does not convert restrictions that are originally
in DNF into modified CNF, because it can optimize on DNF.
For example, suppose an index exists with the first three segments on
columns c1, c2 and c3, in that order. The following expression in
DNF can be used for optimization:
(c1 = 1 AND c2 = 1 AND c3 = 1) OR (c1 = 1 AND c2 = 1 AND
c3 = 2) OR (c1 = 2 AND c2 = 2 AND c3 = 2)
7-6
Restriction Optimization
Modified
Conjunctive
Normal Form
Optimization
Closing Open
Ended Ranges
through
Modified CNF
Optimization
7-7
Performance Reference
Single Join
Condition
Optimization
During optimization, a row is retrieved from table t2. From this row,
the value of column c2 is used to optimize on table t1 according to
the join condition.
If, instead of an index on t1.c1, there is an index on t2.c2, then
t1.c1=t2.c2 could be used to optimize on table t2. In this case, table
t1 would be processed first and the value for t1.c1 would be used to
optimize on table t2 according to the join condition.
In the case that there is an index on t1.c1 as well as an index on t2.c2,
the database engine query optimizer examines the size of both tables
as well as the characteristics of the two indexes and chooses the table
to optimize that will provide the best overall query performance.
7-8
Restriction Optimization
Conjunct with
A Conjunct that consists of a mixture of join conditions and other
Join Conditions Predicates can be used for optimization if it satisfies all of the
following conditions:
Optimization
all the join conditions compare columns from the same two
tables
the conjunct satisfies the requirements for regular Conjunct
Optimization for one of the two tables.
The table that will be optimized through the use of the conjunct will
be processed after the other table referenced.
For example, suppose an index exists on table t1 with the first three
segments on columns c1, c2 and c3, in that order. The following
conjuncts can be used for optimization:
t1.c1
t1.c1
t1.c1
t1.c1
Modified
Conjunctive
Normal Form
with Join
Conditions
Optimization
=
=
=
=
t2.c1
t2.c1
t2.c1
1 AND
For example, suppose an index exists on table t1 with the first three
segments on columns c1, c2 and c3, in that order. The following
expressions in modified CNF can be used for optimization:
(t1.c1 = t2.c1) AND (t1.c2 = t2.c2 OR
(t1.c2 > 2 AND t1.c2 < 5))
(t1.c1 = 1) AND (t1.c2 = t2.c2) AND
(t1.c3 > 2 AND t1.c3 < 5)
7-9
Performance Reference
Closing Join
Condition Open
Ended Ranges
through
Modified CNF
Optimization
Multi-Index
Modified
Disjunct
Optimization
7-10
Push-Down Filters
Push-Down Filters
Push-down filters are strictly an internal optimization technique. By
taking advantage of high speed filtering capabilities, the database
engine can efficiently identify certain rows to be rejected from the
result set depending on characteristics of the restriction. Because
rows are rejected from the result set before they are returned, the
database engine has to analyze fewer rows and completes the
operation faster than it would without push-down filters.
The database engine can use an expression or combination of
expressions as a push-down filter if the following conditions are
satisfied:
7-11
Performance Reference
DISTINCT in
Aggregate
Functions
DISTINCT
Preceding
Selection-list
Relaxed Index
Segment Order
Sensitivity
7-12
For the index to be used to optimize on the ORDER BY, however, the
index segments must be in the order of c2, c1, c3:
SELECT c1, c2, c3 FROM t1 ORDER BY c2, c1, c3
Relaxed
Segment
Ascending
Attribute
Sensitivity
the ASC keyword or neither ASC nor DESC follows the column
in the ORDER BY statement
the corresponding index segment is defined as ascending.
7-13
Performance Reference
t1 ORDER BY c1, c2
t1 ORDER BY c1 DESC, c2 DESC
FROM t1
FROM t1
c1 = 1
t1 ORDER BY c1
t1 ORDER BY c1 DESC
FROM t1
FROM t1
c1 = 1
Search Update
Optimization
7-14
The DISTINCT keyword precedes the selection list and the items
in the selection list are not columns that are the leading segments
of an index.
For example, a temporary table is generated to process the
following query unless an index exists with columns c1 and c2 as
leading segments:
SELECT DISTINCT c1, c2 FROM t1
7-15
Performance Reference
Row Pre-fetch
For definitions of the technical terms used in this chapter, see
Terminology on page 7-18.
Under certain circumstances, upon execution of a SELECT
statement, this release of the database engine attempts to pre-fetch to
the client the first two rows of the resulting rowset. This pre-fetch
greatly improves the performance of fetching data from result sets
that consist of zero or one row.
Pre-fetching rows can be a costly waste of time if the result set
consists of more than one row and the first data retrieval operation
requests a row other than the first row in the result set, such as the
last row. Therefore, pre-fetching is limited to a maximum of two
rows with the goal of improving performance for the cases that
would benefit most while avoiding cases where pre-fetching would
not provide significant benefits.
Pre-fetching occurs only if Array Fetch is enabled in the client DSN
setup options. Array fetching is similar to pre-fetching except that an
array fetch does not occur until the first explicit data retrieval
operation is performed. This difference exists because the first
explicit data retrieval operation may provide enough information to
allow the database engine to extrapolate how the rest of the result set
will be retrieved. For example, if the first data retrieval operation is a
call to the ODBC API SQLFetch, then the database engine can
assume with complete certainty that the entire result set will be
retrieved one record at a time in the forward direction only. This
assumption can be made because, according to the ODBC
specification, an SQLFetch entails that the rest of the result set will be
retrieved via SQLFetch as well. On the other hand, if a
SQLExtendedFetch call is made, and the row set size is greater than
one, then the client assumes that the developer-specified rowset size
is optimal, and it does not override that setting with the array fetch.
Pre-fetching occurs only when all of the following conditions are
satisfied:
7-16
Row Pre-fetch
7-17
Performance Reference
Terminology
This section provides definitions and examples designed to help you
understand the complex technical material in this chapter.
Aggregate Function
An aggregate function uses a group of values in the SELECT or
HAVING clause of a query to produce a single value. Aggregate
functions include: COUNT, AVG, SUM, MAX, MIN, and
DISTINCT.
Closed Range
A closed range is a pair of Open-Ended Ranges joined by an AND
operator. Both open-ended ranges must reference the same column
and one must contain the < or <= comparison operator and the
other must contain the >= or > comparison operator. A BETWEEN
clause also defines a closed range.
For example, the following expressions are closed ranges:
c1 > 1 AND c1 <= 10
c1 BETWEEN 1 AND 10
Conjunct
A conjunct is an expression in which two or more Predicates are
joined by AND operators. For example, the following Restrictions
are conjuncts:
c1=2 AND c2<5
c1>2 AND c1<5 AND c2= abc
7-18
Terminology
Disjunct
A disjunct is an Expression in which two or more Predicates are
joined by OR operators. For example, the following expressions are
disjuncts:
c1 = 2 OR c2 = 5
c1 = 2 OR c1 > 5 OR c2 = abc
Expression
An expression consists of any Boolean algebra allowed in a
Restriction. An entire restriction or any part of the restriction that
includes at least one or more complete Predicates is an expression.
Index
An index is a construct associated with one or more columns in a
table that allows the database engine to perform efficient searches
and sorts. The database engine can make use of indexes to improve
search performance by reading only specific rows that will satisfy the
search conditions rather than by examining all the rows in the table.
The database engine can make use of indexes to retrieve rows in the
order specified by an SQL query rather than having to use inefficient
techniques to order the rows after retrieving them.
Join Condition
A join condition is a Predicate that compares a column in one table
to a column in another table using any of the comparison operators:
<, <=, =, >=, >.
For example, the following predicates are join conditions:
t1.c1 = t2.c1
t1.c1 > t2.c2
7-19
Performance Reference
Leading Segments
A group of index segments are leading segments if they consist of the
first n columns in an Index, where n is any number up to and
including the total number of segments in the index. For example, if
an index is defined with segments on columns c1, c2, and c4, then c1
is a leading segment, c1 and c2 together are leading segments, and all
three together are leading segments. c2 alone is not a leading
segment, because the segment c1 precedes c2 and is excluded.
Columns c1 and c4 together are not leading segments, because c2
precedes c4 and is excluded.
Modified Conjunctive Normal Form (Modified CNF)
An Expression in Modified Conjunctive Normal Form is like an
expression in Conjunctive Normal Form (CNF) except that each
Disjunct may contain Closed Ranges as well as Predicates.
For example, the following expressions are in Modified CNF:
c1 = 2 AND c2 < 5
(c1 = 2 OR (c1 > 4 AND c1 < 6) OR c1 = 10) AND (c2 = 1
OR c3 = efg)
Modified Disjunct
A modified disjunct is like a Disjunct except that it may contain
Closed Ranges as well as Predicates.
For example, the following expressions are modified disjuncts:
c1 = 2 OR (c1 > 4 AND c1 < 5)
(c1 = 2 OR (c1 > 4 AND c1 < 5)) OR c2 = abc
Open-Ended Range
An open-ended range is a Predicate that contains any of the
following comparison operators: <, <=, >= or >. Furthermore, one
of the predicates operands must consist entirely of a single column
and the other operand must consist entirely of either a single column
from another table or a literal.
For example, the following expressions are open ended ranges:
c1 > 1
c1 <= 10
t1.c1 > t2.c1
7-20
Terminology
Predicate
A predicate is a Boolean expression that does not include any AND
or OR Boolean operators (with the exception of a BETWEEN
predicate).
For example, the following expressions are predicates:
(c1 = 1)
(c1 LIKE abc)
(c1 BETWEEN 1 AND 2)
Restriction
A restriction is the entire WHERE clause of an SQL query.
7-21
Performance Reference
7-22
Appendix
Data Types
This appendix describes the data types and data type mappings
offered by Pervasive PSQL through the ODBC interface and the
Btrieve interface.
A-1
Data Types
Transactional
Type (Size)
Relational Type
Type
Code2
Size
(bytes)
AUTOINC(2)
SMALLIDENTITY
SQL_SMALLINT(5)
15
AUTOINC(4)
IDENTITY
SQL_INTEGER(4)
15
BFLOAT(4)
BFLOAT4
SQL_REAL(7)
not null
BFLOAT(8)
BFLOAT8
SQL_DOUBLE(8)
not null
BLOB
LONGVARBINARY
SQL_LONGVARBINARY
(-4)
21
n/a3
not null
2, 3, 6
CLOB
LONGVARCHAR
SQL_LONGVARCHAR
(-1)
21
n/a3
not null
case
insensitive
5, 6
CURRENCY
CURRENCY
SQL_DECIMAL(3)
19
not null
DATE
DATE
SQL_DATE(9)
not null
none
DATETIME
SQL_TIMESTAMP(11)
30
not null
DECIMAL
DECIMAL
SQL_DECIMAL(3)
1 - 64
precision
scale
not null
FLOAT(4)
REAL
SQL_REAL(7)
not null
FLOAT(8)
DOUBLE
SQL_DOUBLE(8)
not null
GUID
UNIQUEIDENTIFIER SQL_GUID(-11)
27
16
not null
INTEGER(1)
TINYINT
SQL_TINYINT(-6)
not null
INTEGER(2)
SMALLINT
SQL_SMALLINT(5)
not null
A-2
Create/Add Notes
Parameters4
10
Table A-1
Pervasive PSQL Data Types and Equivalent ODBC Data Types continued
Transactional
Type (Size)
Relational Type
Type
Code2
Size
(bytes)
Create/Add Notes
Parameters4
INTEGER(4)
INTEGER
SQL_INTEGER(4)
not null
INTEGER(8)
BIGINT
SQL_DECIMAL(3)
not null
NUMERIC
NUMERIC
SQL_NUMERIC(2)
1 - 15
precision
scale
not null
NUMERICSA
NUMERICSA
SQL_NUMERIC(2)
18
1 - 15
precision
scale
not null
NUMERICSTS
NUMERICSTS
SQL_NUMERIC(2)
17
1- 14
precision
scale
not null
STRING
BINARY
SQL_BINARY(-2)
1- 8,000 size
not null
case
insensitive
2, 3
STRING
CHAR
SQL_CHAR(1)
1- 8,000 size
not null
case
insensitive
TIME
TIME
SQL_TIME(10)
not null
TIMESTAMP
TIMESTAMP
SQL_TIMESTAMP(11)
20
not null
UNSIGNED(1)
BINARY
UTINYINT
SQL_TINYINT(-6)
14
not null
UNSIGNED(2)
BINARY
USMALLINT
SQL_SMALLINT(5)
14
not null
UNSIGNED(4)
BINARY
UINTEGER
SQL_INTEGER(4)
14
not null
UNSIGNED(8)
BINARY
UBIGINT
SQL_DECIMAL(3)
14
not null
WSTRING
25
n/a3
WSZSTRING
26
n/a3
A-3
Data Types
Table A-1
Pervasive PSQL Data Types and Equivalent ODBC Data Types continued
Transactional
Type (Size)
Relational Type
Type
Code2
Size
(bytes)
ZSTRING
VARCHAR
SQL_VARCHAR(12)
11
1- 8,000 size
not null
case
insensitive
none
BIT
SQL_BIT(-7)
16
1 bit
6, 8
LOGICAL(1)
BIT
SQL_BIT(-7)
1 bit
LOGICAL(2)
SMALLINT
SQL_SMALLINT(5)
Create/Add Notes
Parameters4
not null
The required parameters are precision and size. The optional parameters are case insensitive, not null, and
scale.
Notes:
1. Padded with spaces
2. Flag set in FIELD.DDF to tell SQL to use binary
3. Padded with binary zeros
4. Cannot be used as variable or in stored procedures
5. Not padded
6. Cannot be indexed
7. Transactional only
8. TRUEBITCREATE must be set to "on" (the default)
9. TRUEBITCREATE must be set to "off"
10. Type code 30 is not a transactional interface type code. It is the identifier for DATETIME within the relational
interface metadata
A-4
Data Type
Ranges
Table A-2
The following table lists the value range for the Pervasive PSQL data
types.
BFLOAT4
-1.70141172e+38 +1.70141173e+38
The smallest value by which you can increment or decrement a BLOAT4 is
2.938736e-39
BFLOAT8
-1.70141173e+38 +1.70141173e+38
The smallest value by which you can increment or decrement a BLOAT8 is
2.93873588e-39
BIGINT
-9223372036854775808 +9223372036854775807
BINARY
BIT
STRING
CURRENCY
-922337203685477.5808 +922337203685477.5807
DATE
01-01-0001 12-31-9999
DATETIME
January 1, 1753 through December 31, 9999, to an accuracy of one threehundredth of a second
DECIMAL
DOUBLE
-1.7976931348623157e+308 +1.7976931348623157e+308
The smallest value by which you can increment or decrement a DOUBLE is
2.2250738585072014e-308
FLOAT
-1.7976931348623157E+308 +1.7976931348623157E+308
The smallest value by which you can increment or decrement a FLOAT is
2.2250738585072014e-308
IDENTITY
+1 +2147483647
INTEGER
-2147483648 +2147483647
LOGICAL
LONGVARBINARY
LONGVARCHAR
MONEY
-99999999999999999.99 +99999999999999999.99
A-5
Data Types
Table A-2
NUMERIC
Depends on the length and number of decimal places. See Precision and Scale of
Decimal Data Types on page A-9.
NUMERICSA
Depends on the length and number of decimal places. See Precision and Scale of
Decimal Data Types on page A-9.
NUMERICSTS
Depends on the length and number of decimal places. See Precision and Scale of
Decimal Data Types on page A-9.
REAL
-3.4028234E+38 +3.4028234e+38
The smallest value by which you can increment or decrement a REL is 1.4E-45
SMALLIDENTITY
+1 +32767
SMALLINT
-32768 +32767
TIME
00:00:00 23:59:59
TIMESTAMP
TINYINT
-128 +127
UBIGINT
0 18446744073709551615
UINTEGER
0 4294967295
UNIQUEIDENTIFIER
USMALLINT
0 65535
UTINYINT
0 255
VARCHAR
Operator
Precedence
A-6
NOT
AND
= (assignment)
Parentheses
You may use parentheses to override the defined precedence of the
operators in an expression. Everything within the parentheses is
evaluated first to yield a single value. The value may then be used by
an operator outside of the parentheses.
For example, in the SET statement in the following procedure, the
division operator would ordinarily be evaluated before the addition
operator. The result would be 12 (that is, 8 + 4). However, the
addition is performed first because of the parentheses, so the
procedure returns a result of 4.
A-7
Data Types
CREATE PROCEDURE checkvalue1();
BEGIN
DECLARE :Counter INTEGER;
SET :Counter = 32 / (4 + 4);
PRINT :Counter;
END
CALL checkvalue1
Data Type
Precedence
Data type precedence determines which data type results when two
expressions of different data types are combined by an operator. The
data type with the lower precedence is converted to the data type
with the higher precedence.
Note Pervasive PSQL returns an error if you perform an
A-8
LONGVARCHAR
CHAR, VARCHAR
DATETIME
TIMESTAMP
DATE
TIME
Precision and
Scale of
Decimal Data
Types
A-9
Data Types
types, the precedence rules determine the data type of the result. The
result has the precision and scale defined for its data type.
The result is a DECIMAL for the following conditions:
Table A-3 defines how precision and scale are derived when the result
of an operation is of data type DECIMAL. Exp stands for
expression, s stands for scale, and p stands for precision.
Table A-3
Operation
Precision
Scale
max(s1, s2)
max(s1, s2)
p1 + p2 + 1
s1 + s2
p1 - s1 + s2 + max(6, s1 + p2 +1)
max(6, s1 + p2 +1)
max(s1, s2)
Truncation
A-10
CHAR,
VARCHAR, and
LONGVARCHAR
BINARY and
LONGVARBINARY
UINT,
Clob1 LONGVARCHAR,
Clob2 LONGVARCHAR,
A-11
Data Types
[Fixed Data (Nbr, Clob1header, Clob2header,
Blob1header)][ClobData1][ClobData2][BlobData1]
As you can see, the variable length portion of the data is not in the
column order for the existing data.
For newly inserted records, however, the variable length portion of
the data is in the column order for the existing data. This assumes
that all columns have data assigned (the columns are not NULL).
[Fixed Data (Nbrheader, Clob1header, Clob2header,
Blob1header)][NbrClobData][ClobData1][ClobData2]
[BlobData1]
Limitations on
The following limitations apply to the LONGVARCHAR and
LONGVARBINARY data types:
LONGVARCHAR
and
A-12
DATETIME
The DATETIME data type represents a date and time value. The data
type is stored internally as two 4-byte integers. The first four bytes
store the number of days before or after the base date of January 1,
1900. The other four bytes store the time of day represented as the
number of milliseconds after midnight.
The DATETIME data type can be indexed. The accuracy of
DATETIME is one three-hundredth of a second.
DATETIME is a relational data type only. No corresponding
transactional data type (Btrieve type) is available.
Format of DATETIME
The only permissible format for DATETIME is YYYY-MM-DD
HH:MM:SS.mmm. (The CONVERT function contains an optional
parameter that allows you to truncate the milliseconds portion of
DATETIME. See the "Convert" function under Conversion
Functions on page 5-20.)
The following table indicates the data components and their valid
values for DATETIME.
Table A-4
Component
Valid Values
YEAR (YYYY)
1753 to 9999
MONTH (MM)
01 to 12
DAY (DD)
01 to 31
HOUR (HH)
00 to 23
MINUTE (MM)
00 to 59
SECOND (SS)
00 to 59
MILLISECOND (mmm)
000 to 999
A-13
Data Types
Millisecond Rounding
The following table explains the rounding used for milliseconds.
Table A-5
Millisecond Rounding
Last Digit of
Millisecond
Rounding Rule
for Last Digit
Example
0, 1
2, 3, 4
5, 6, 7, 8
Operand 2
DATE
DATETIME
TIME
TIMESTAMP
Operand 1
A-14
BFLOAT4
DATETIME
TIMESTAMP
BFLOAT8
DATETIME
TIMESTAMP
BIGINT
DATETIME
BINARY
BIT
CHAR
Table A-6
Operand 2
DATE
DATETIME
TIME
TIMESTAMP
Operand 1
CURRENCY
DATETIME
DATE
DATETIME
DECIMAL
DATETIME
DOUBLE
DATETIME
TIMESTAMP
IDENTITY
DATETIME
TIMESTAMP
INTEGER
DATE
LONGVARBINARY
LONGVARCHAR
MONEY
DATETIME
NUMERIC
DATETIME
NUMERICSA
NUMERICSTS
REAL
DATETIME
TIMESTAMP
SMALLIDENTITY
DATE
DATETIME
TIMESTAMP
SMALLINT
DATE
DATETIME
TIMESTAMP
TIME
TIMESTAMP
TINYINT
DATE
DATETIME
TIMESTAMP
UBIGINT
DATE
DATETIME
TIMESTAMP
UINTEGER
DATE
DATETIME
TIMESTAMP
A-15
Data Types
Table A-6
Operand 2
DATE
DATETIME
TIME
TIMESTAMP
Operand 1
UNIQUEIDENTIFIER
USMALLINT
DATE
DATETIME
TIMESTAMP
UTINYINT
DATE
DATETIME
TIMESTAMP
VARCHAR
CONVERT From
DATE
DATETIME
TIME
TIMESTAMP
VARCHAR
A-16
Table A-8
CAST From
DATE
DATETIME
TIME
TIMESTAMP
VARCHAR
If you provide a quoted string, all 32 digits are required. The database
engine does not pad a partial string.
A-17
Data Types
Meaning
Equals
<> or !=
Not equal to
<
Less than
>
Greater than
<=
>=
IS NULL
IS NOT NULL
CHAR
LONGVARCHAR
VARCHAR
A-18
Infinity Representation
Value
Float
Hexadecimal
Float
Character
Double Hexadecimal
Maximum Positive
0x7FEFFFFFFFFFFFFF
Maximum Negative
0xFFEFFFFFFFFFFFFF
Double
Character
Infinity Positive
0x7F800000
1E999
0x7FF0000000000000
1E999
Infinity Negative
0xFF800000
-1E999
0xFFF0000000000000
-1E999
A-19
Data Types
Legacy Type
Type Code
Replaced by
Type Code
LOGICAL(1)
BIT
14
LOGICAL(2)
SMALLINT
14
LSTRING
10
VARCHAR
11
LVAR
13
LONGVARCHAR
21
NOTE
12
LONGVARCHAR
21
Existing databases that use these data types are supported and
function correctly. New databases, however, cannot create tables
with the legacy data types.
A-20
Data Type
Type Code
AUTOINC
15
BFLOAT
BLOB
21
STRING
CLOB
21
CURRENCY
19
DATE
DECIMAL
FLOAT
GUID
27
A-21
Data Types
Table A-11
Data Type
Type Code
INTEGER
LOGICAL
LSTRING
10
MONEY
NUMERIC
NUMERICSA
18
NUMERICSTS
17
TIME
TIMESTAMP
20
UNSIGNED BINARY
14
WSTRING
25
WZSTRING
26
ZSTRING
11
AUTOINC
The AUTOINC key type is a signed Intel integer that can be either
two or four bytes long. Internally, AUTOINC keys are stored in Intel
binary integer format, with the high-order and low-order bytes
reversed within a word. The MicroKernel sorts AUTOINC keys by
their absolute (positive) values, comparing the values stored in
different records a word at a time from right to left. AUTOINC keys
may be used to automatically assign the next highest value when a
record is inserted into a file. Because the values are sorted by absolute
value, the number of possible records is roughly half what you would
expect given that the data type is signed.
Values that have been deleted from the file are not re-used
automatically. If you indicate that you want the database engine to
assign the next value by entering a zero (0) value in an insert or
update, the database simply finds the highest number, adds 1, and
inserts the resulting value.
A-22
You can initialize the value of a field in all or some records to zero and
later add an index of type AUTOINC. This feature allows you to
prepare for an AUTOINC key without actually building the index
until it is needed.
When you add the index, the MicroKernel changes the zero values in
each field appropriately, beginning its numbering with a value equal
to the greatest value currently defined in the field, plus one. If
nonzero values exist in the field, the MicroKernel does not alter
them. However, the MicroKernel returns an error status code if
nonzero duplicate values exist in the field.
The MicroKernel maintains the highest previously used autoincrement value associated with each open file containing an
AUTOINC key. This value is established and increments only when
an INSERT operation occurs for a record with ASCII zeros in the
AUTOINC field. The value is used by all clients so that concurrent
changes can take place, taking advantage of Key Page Concurrency.
The next AUTOINC value for a file is raised whenever any INSERT
occurs that uses the previous AUTOINC value. This happens
whether or not the INSERT is in a transaction or the change is
committed.
However, this value may be lowered during an INSERT if all of the
following are true:
The highest AUTOINC value found in the key is lower than the
next AUTOINC value for the file
No other client has a pending transaction affecting the page that
contains the highest AUTOINC value
The key page containing the highest AUTOINC value is not
already pending by the client doing the INSERT.
In other words, only the first INSERT within a transaction can lower
the next available AUTOINC value. After that, the next available
AUTOINC value just keeps increasing.
An example helps clarify how an AUTOINC value may be lowered.
Assume an autoincrement file exists with records 1, 2, 3 and 4. The
next available AUTOINC value is 5.
Client1 begins a transaction and inserts two new records, raising the
next available AUTOINC value to 7. (Client1 gets values 5 and 6).
Client2 begins a transaction and also inserts two new records. This
A-23
Data Types
A-24
BFLOAT
The BFLOAT key type is a single or double-precision real number. A
single-precision real number is stored with a 23-bit mantissa, an 8bit exponent biased by 128, and a sign bit. The internal layout for a
4-byte float is as follows:
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
8-bit exponent
23-bit mantissa
Sign
A-25
Data Types
BLOB
The Binary Large Object (BLOB) type provides support for binary
data fields up to 2 GB in size. This type consists of 2 parts:
referred to as STRING
The CHAR key type is a sequence of characters ordered from left to
right. Each character is represented in ASCII format in a single byte,
except when the MicroKernel is determining whether a key value is
null. CHAR data is expected to be padded with blanks to the full size
of the key.
CLOB
The Character Large Object (CLOB) type provides support for
character data fields up to 2 GB in size. This type consists of 2 parts:
A-26
A-27
Data Types
1 1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
digit
1
digit
2
byte n-1
byte 1
digit
3
...
...
...
digit
4
digit
2n-1
sign
nibble
The sign nibble is either 0xF or 0xC for positive numbers and 0xD for
negative numbers. Pervasive ODBC and Pervasive ActiveX controls
always use 0xF for the positive sign nibble. The decimal point is
implied; no decimal point is stored in the DECIMAL field. Your
application is responsible for tracking the location of the decimal
point for the value in a DECIMAL field. All the values for a
DECIMAL key type must have the same number of decimal places in
order for the MicroKernel to collate the key correctly. The DECIMAL
type is commonly used in COBOL applications.
An eight-byte decimal can hold 15 digits plus the sign. A ten-byte
decimal can hold 19 digits plus the sign. The decimal value is
expected to be left-padded with zeros.
FLOAT
Caution Precision beyond that supported by the C-language
A-28
The FLOAT key type is consistent with the IEEE standard for single
and double-precision real numbers. The internal format for a 4-byte
FLOAT consists of a 23-bit mantissa, an 8-bit exponent biased by
127, and a sign bit, as follows:
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
8-bit exponent
23-bit mantissa
Sign
11-bit exponent
20-bit mantissa
Sign
bytes 3-0:
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
32-bit mantissa
GUID
The GUID data type is a 16-byte number that is stored internally as
a 16-byte binary value. Its extended data type value is 27.
GUIDs are commonly used as globally unique identifiers. The
corresponding data type for the relational interface is
UNIQUEIDENTIFIER. (See UNIQUEIDENTIFIER on page A17.)
A-29
Data Types
The sort order for the bytes composing the GUID are compared in
the following sequence: 10, 11, 12, 13, 14, 15, 8, 9, 6, 7, 4, 5, 0, 1, 2, 3.
The key segment length for a GUID must be 16 bytes. See Key
Specification Blocks on page 2-23 in Btrieve API Guide, which is
part of the Pervasive PSQL software development kit (SDK).
INTEGER
The INTEGER key type is a signed whole number and can contain
any number of digits. Internally, INTEGER fields are stored in Intel
binary integer format, with the high-order and low-order bytes
reversed within a word. The MicroKernel evaluates the key from
right to left. The sign must be stored in the high bit of the rightmost
byte. The INTEGER type is supported by most development
environments.
Table A-12
Length in Bytes
Value Ranges
0 255
-32768 32767
-2147483648 2147483647
-9223372036854775808 9223372036854775807
LOGICAL
The LOGICAL key type is stored as a 1 or 2-byte value. The
MicroKernel collates LOGICAL key types as strings. Doing so allows
your application to determine the stored values that represent true or
false.
LSTRING
The LSTRING key type has the same characteristics as a regular
STRING type, except that the first byte of the string contains the
binary representation of the strings length. The LSTRING key type
is limited to a maximum size of 255 bytes. The length stored in byte
0 of an LSTRING key determines the number of significant bytes.
A-30
The database engine ignores any values beyond the specified length
of the string when sorting or searching for values. The LSTRING
type is commonly used in legacy Pascal applications.
MONEY
The MONEY key type has the same internal representation as the
DECIMAL type, with an implied two decimal places.
NUMERIC
Each digit of a NUMERIC data type occupies one byte. NUMERIC
values are stored as ASCII strings and right justified with leading
zeros. The rightmost byte of the number includes an embedded sign
with an EBCDIC value. By default, the sign value for positive
NUMERIC data types is an unsigned numeric number. The
NUMERIC type is commonly used in COBOL applications.
Optionally, you may specify that you want to shift the value of the
sign for positive NUMERIC data types. The following table
compares the sign values in the default (unshifted) and shifted states.
Table A-13
Digit
Positive
Negative
Positive
Negative
A-31
Data Types
Server Platform
Setting Specification
Windows 32-bit
Using the registry editor provided with the operating system, add the DBCobolNumeric
setting to the registry as a new string value to the following key:
HKEY_LOCAL_MACHINE/SOFTWARE/PERVASIVE SOFTWARE/DATABASE
NAMES/VERSION x/ SETTINGS
(where x represents the version number)
Set the string value to yes.
Note: In most Windows operating systems, the Pervasive Software key is
HKEY_LOCAL_MACHINE\SOFTWARE\PERVASIVE SOFTWARE. However, its location
under HKEY_LOCAL_MACHINE\SOFTWARE can vary depending on the operating system.
Caution: Editing the registry is an advanced procedure. If done improperly, the editing
could cause your operating system not to boot. If necessary, obtain the services of a
qualified technician to perform the editing. Pervasive Software does not accept
responsibility for a damaged registry.
Stop and restart the database engine or the engine services. See Starting and Stopping
the Server Engine on a Windows Server on page 2-2 and Starting and Stopping the
Workgroup Engine on Windows on page 2-5, both in Pervasive PSQL User's Guide.
Linux
Add the DBCobolNumeric setting to bti.ini below the [Database Names] entry:
[Database Names]
DBCobolNumeric=yes
By default, bti.ini is located in the /usr/local/psql/etc directory.
Stop and restart the database engine. Starting and Stopping the Database Engine on
Linux on page 2-7 in Pervasive PSQL User's Guide.
You may already have positive NUMERIC data with the sign value in
the default (unshifted) format. If you set DBCobolNumeric to yes
and continue adding data to the same table, mixed formats result.
Leaving your data with mixed formats for the sign value is not
recommended.
A-32
Negative
1 or Q
2 or R
3 or S
4 or T
5 or U
6 or V
7 or W
8 or X
9 or Y
0 or P
A-33
Data Types
NUMERICSTS
The NUMERICSTS key type (sometimes called SIGN TRAILING
SEPARATE) is a COBOL data type that has values resembling those
of the NUMERIC data type. NUMERICSTS values are stored as
ASCII strings and right justified with leading zeros. However, the
rightmost byte of a NUMERICSTS string is either + (ASCII 0x2B)
or - (ASCII 0x2D). This differs from NUMERIC values that embed
the sign in the rightmost byte along with the value of that byte.
REAL
The REAL type is defined as a 4-byte FLOAT.
TIME
The TIME key type is stored internally as a 4-byte value. Hundredths
of a second, second, minute, and hour values are each stored in 1byte binary format. The MicroKernel places the hundredths of a
second value into the first byte, followed respectively by the second,
minute, and hour values.
A-34
TIMESTAMP
The TIMESTAMP data type represents a time and date value. In SQL
applications, use this data type to stamp a record with the time and
date of the last update to the record.
Note According to the ODBC standard, scalar functions such as
TIMESTAMP Components
YEAR
0001 to 9999
MONTH
01 to 12
DAY
HOUR
00 to 23
MINUTE
00 to 59
SECOND
00 to 59
A-35
Data Types
A-36
UNSIGNED BINARY
UNSIGNED BINARY keys can be any number of bytes up to the
maximum key length of 255. UNSIGNED keys are compared bytefor-byte from the most significant byte to the least significant byte.
The first byte of the key is the least significant byte. The last byte of
the key is the most significant.
The database engine sorts UNSIGNED BINARY keys as unsigned
INTEGER keys. The differences are that an INTEGER has a sign bit,
while an UNSIGNED BINARY type does not, and an UNSIGNED
BINARY key can be longer than 4 bytes.
WSTRING
WSTRING is a Unicode string that is not null-terminated. The
length of the string is determined by the field length. WSTRING is
not supported in SQL.
WZSTRING
WZSTRING is a Unicode string that is double null-terminated. The
length of this string is determined by the position of the Unicode
NULL (two null bytes) within the field. This corresponds to the
ZSTRING type supported in Btrieve. WZSTRING is not supported
in SQL.
ZSTRING
The ZSTRING key type corresponds to a C string. It has the same
characteristics as a regular string type except that a ZSTRING type is
terminated by a binary 0. The MicroKernel ignores any values
beyond the first binary 0 it encounters in the ZSTRING, except when
the MicroKernel is determining whether a key value is null.
The maximum length of a ZSTRING type is 255 characters,
including the null terminator character. If used as a key for a nullable
column, only the first 254 bytes of the string are used in the key. This
minor limitation occurs because the key is limited to 255 bytes total
length, and one byte is occupied by the null indicator for the column,
leaving only 254 bytes for the key value.
A-37
Data Types
A-38
Appendix
Reserved words are SQL keywords and other symbols that have
special meanings when they are processed by the SRDE. Reserved
words are not recommended for use as database, table, column,
variable or other object names. If a reserved word is used as an object
name, it must be enclosed in double-quotes to notify the SRDE that
the word is not being used as a keyword in the given context.
You can avoid having to worry about reserved words by always
enclosing user-defined object names in double-quotes.
This appendix contains the following topic:
B-1
Reserved Words
Each of the symbols or words listed below has a special meaning
when processed by the SRDE, unless it is delimited by doublequotes. Using one of these words as a table or object name without
double quotes will cause an error.
See also the next section, Words to Avoid on page B-7.
Symbols
#
A
ABORT
ACCELERATED
ADD
AFTER
ALL
ALTER
AND
ANY
AS
ASC
ATOMIC
AVG
BEFORE
BEGIN
BETWEEN
BORDER
BY
B-2
CALL
CASCADE
CASE
CAST
CHECK
CLOSE
COALESCE
COLLATE
COLUMN
COMMIT
COMMITTED
CONSTRAINT
CONVERT
COUNT
CREATE
CREATESP
CREATETAB
CREATEVIEW
CROSS
CS
CURDATE
CURRENT
CURSOR
CURTIME
Reserved Words
D
DATABASE
DCOMPRESS
DDF
DECIMALSEPARATORCOMMA
DECLARE
DEFAULT
DEFAULTCOLLATE
DELETE
DENY
DESC
DIAGNOSTICS
DICTIONARY
DISTINCT
DO
DROP
DSN
E
EACH
ELSE
END
ENFORCED
EX
EXCLUSIVE
EXEC
EXECUTE
EXISTING
FETCH
FN
FOR
FOREIGN
FROM
FULL
EXISTS
FUNCTION
G
GRANT
GROUP
H
HANDLER
HAVING
B-3
I
IF
IN
INDEX
INNER
INOUT
INSERT
INTEGRITY
INTERNAL
INTO
IS
ISOLATION
JOIN
K
KEY
L
LEAVE
LEFT
LEGACYOWNERNAME
LEVEL
LIKE
LOGIN
MAX
MIN
MODE
MODIFIABLE
MODIFY
LOOP
N
NEW
NEXT
NO
NORMAL
NOT
NOW
NULL
B-4
Reserved Words
O
OF
OFF
OLD
ON
ONLY
OPEN
OR
ORDER
OUT
OUTER
OWNER
P
PAGESIZE
PARTIAL
PRIMARY
PROCEDURE
PUBLIC
READ
REFERENCES
REFERENCING
RELATIONAL
RELEASE
REPEAT
REPEATABLE
REPLACE
RESTRICT
RETURN
RETURNS
REVOKE
RIGHT
ROLLBACK
ROW
SAVEPOINT
SECURITY
SELECT
SERIALIZABLE
SET
SIGNAL
SIZE
SQLSTATE
SSP_EXPR
SSP_PRED
START
SUM
SVBEGIN
SVEND
ROWCOUNT
B-5
T
T
TABLE
THEN
TO
TOP
TRANSACTION
TRIGGER
TRIGGERSTAMPMISC
TRUEBITCREATE
TRUENULLCREATE
TS
U
UNCOMMITTED
UNION
UNIQUE
UNIQUEIDENTIFIER
UNTIL
UPDATE
USER
USING
V
VALUES
VIEW
B-6
WHEN
WHERE
WHILE
WITH
WORK
WRITE
Words to Avoid
Words to Avoid
The following table lists common keywords from the SQL-92 and
SQL-99 ANSI standards. While Pervasive PSQL may not support or
offer all of these keywords, you should avoid using these words as
names for tables, columns, or other objects, if you do not use doublequotes around them. Pervasive reserves the right to add support for
any of these keywords as well as any future ANSI SQL keywords in
future releases.
If you use double-quotes to delimit all table, column, and userdefined object names, you do not need to worry about possible
future conflicts with reserved words.
See also the previous section, Reserved Words on page B-2.
Table B-1
ABSOLUTE
ACTION
ADD
ALL
ALLOCATE
ALTER
AND
ANY
ARE
AS
ASC
ASSERTION
AT
AUTHORIZATION
AVG
BEGIN
BETWEEN
BIT
BIT_LENGTH
BOTH
BY
CASCADE
CASCADED
CASE
CAST
CATALOG
CHAR
CHARACTER
CHAR_LENGTH
CHARACTER_LENGTH
CHECK
CLOSE
COALESCE
COLLATE
COLLATION
COLUMN
COMMIT
CONNECT
CONNECTION
CONSTRAINT
CONSTRAINTS
CONTINUE
CONVERT
CORRESPONDING
COUNT
CREATE
CROSS
CURRENT
B-7
Table B-1
B-8
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
CURRENT_USER
CURSOR
DATE
DAY
DEALLOCATE
DEC
DECIMAL
DECLARE
DEFAULT
DEFERRABLE
DEFERRED
DELETE
DESC
DESCRIBE
DESCRIPTOR
DIAGNOSTICS
DISCONNECT
DISTINCT
DOMAIN
DOUBLE
DROP
ELSE
END
END-EXEC
ESCAPE
EXCEPT
EXCEPTION
EXEC
EXECUTE
EXISTS
EXTERNAL
EXTRACT
FALSE
FETCH
FIRST
FLOAT
FOR
FOREIGN
FOUND
FROM
FULL
FUNCTION
GET
GLOBAL
GO
GOTO
GRANT
GROUP
HAVING
HOUR
IDENTITY
IMMEDIATE
IN
INDICATOR
INITIALLY
INNER
INPUT
INSENSITIVE
INSERT
INT
INTEGER
INTERSECT
INTERVAL
INTO
IS
ISOLATION
JOIN
KEY
LANGUAGE
LAST
LEADING
LEFT
LEVEL
LIKE
LOCAL
Words to Avoid
Table B-1
LOWER
MASK
MATCH
MAX
MIN
MINUTE
MODULE
MONTH
NAMES
NATIONAL
NATURAL
NCHAR
NEXT
NO
NOT
NULL
NULLIF
NUMERIC
OCTET_LENGTH
OF
ON
ONLY
OPEN
OPTION
OR
ORDER
OUTER
OUTPUT
OVERLAPS
PAD
PARTIAL
POSITION
PRECISION
PREPARE
PRESERVE
PRIMARY
PRIOR
PRIVILEGES
PROCEDURE
PUBLIC
READ
REAL
REFERENCES
RELATIVE
RESTRICT
REVOKE
RIGHT
ROLLBACK
ROWS
SCHEMA
SCROLL
SECOND
SECTION
SELECT
SESSION
SESSION_USER
SET
SIZE
SMALLINT
SOME
SPACE
SQL
SQLCODE
SQLERROR
SQLSTATE
SUBSTRING
SUM
SYSTEM_USER
TABLE
TEMPORARY
THEN
TIME
TIMESTAMP
TIMEZONE_HOUR
TIMEZONE_MINUTE
TO
TRAILING
TRANSACTION
B-9
Table B-1
TRANSLATE
TRANSLATION
TRIM
TRUE
UNION
UNIQUE
UNKNOWN
UPDATE
UPPER
USAGE
USER
USING
VALUE
VALUES
VARCHAR
VARYING
VIEW
WHEN
WHENEVER
WHERE
WITH
WORK
WRITE
YEAR
ZONE
B-10
Appendix
System Tables
C-1
System Tables
Overview
The information used by Pervasive PSQL and its components is
stored in special tables called system tables.
Caution Do not attempt to modify system tables with DELETE,
UPDATE, or INSERT statements, or user-defined triggers.
System tables should never be altered directly.
Note that the Pervasive PSQL APIs are documented in the Pervasive
PSQL Software Development Kit (SDK). The SDK components are
compatible with the database engine from release to release. The
format of the system tables depends on the internal architecture of
the Pervasive PSQL database engine. The architecture may change
from release to release. Application that directly access
undocumented columns of system tables may have to be changed if
the internal architecture of Pervasive PSQL changes.
For each system table, the following table indicates the name of the
associated file and briefly describes the system tables contents.
Note Some data in the system tables cannot be displayed. User
C-2
Overview
Table C-1
System Tables
System Table
Dictionary File
Contents
V11
V22
X$Attrib
ATTRIB.DDF
PVATTRIB.DDF
X$Depend
DEPEND.DDF
PVDEPEND.DDF
X$Field
FIELD.DDF
PVFIELD.DDF
X$File
FILE.DDF
PVFILE.DDF
X$Index
INDEX.DDF
PVINDEX.DDF
Index definitions.
X$Proc
PROC.DDF
PVPROC.DDF
X$Relate
RELATE.DDF
PVRELATE.DDF
X$Rights
RIGHTS.DDF
PVRIGHTS.DDF
X$Trigger
TRIGGER.DDF
PVTRIG.DDF
Trigger information.
X$User
USER.DDF
PVUSER.DDF
X$View
VIEW.DDF
PVVIEW.DDF
View definitions.
1Applies
2Applies
Pervasive PSQL creates all of the system tables when you create a
database.
Two other system tables that you may encounter are VARIANT.DDF
and OCCURS.DDF (for a V1 database) and PVVARIANT.DDF and
PVOCCURS.DDF (for a V2 database).These two system files are
used for COBOL support and do not require any direct intervention
by a user. Future versions of the utilities for COBOL may implement
a different architecture, in which case these system tables may no
longer be required. See also SQL Access for COBOL Applications
on page D-1.
C-3
System Tables
V1 Metadata
System Tables
Table C-2
X$Attrib
The X$Attrib system table is associated with the file ATTRIB.DDF.
X$Attrib contains information about the column attributes of each
column in the database; there is an entry for each column attribute
you define. The structure of X$Attrib is described in X$Attrib
System Table Structure:
Column Name
Type
Size
Case Insensitive
Description
Xa$Id
USMALLINT
not applicable
Xa$Type
CHAR
No
Xa$ASize
USMALLINT
not applicable
Xa$Attrs
LONGVARCHAR
(NOTE)
<=2048
not applicable
1Attribute
type C, H, M, R and V are legacy validation types valid only in a Pervasive.SQL 7 or Scalable SQL
environment. Pervasive PSQL releases newer than Pervasive.SQL 7 use only the D (default) and O (column
collation) attributes.
C-4
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xa$Id
No
not applicable
Yes
Xa$Type
No
No
No
X$Depend
The X$Depend system table is associated with the file
DEPEND.DDF. X$Depend contains information about trigger
dependencies such as tables, views, and procedures. The structure of
X$Depend is as follows:
Table C-4
Column Name
Type
Size
Case Insensitive
Description
Xd$Trigger
CHAR
30
Yes
Xd$DependType
UNSIGNED
not applicable
Xd$DependName
CHAR
30
Yes
Index Number
Segment
Number
Column Name
Duplicates
Case Insensitive
Segmented
Xd$Trigger
No
Yes
Yes
Xd$DependType
No
not applicable
Yes
Xd$DependName
No
Yes
No
Xd$DependType
Yes
not applicable
Yes
Xd$DependName
Yes
Yes
No
C-5
System Tables
Column Name
Type
Size
Case Insensitive
Description
Xe$Id
USMALLINT
not applicable
Xe$File
USMALLINT
not applicable
Xe$Name
CHAR
20
Yes
Xe$DataType
UTINYINT
not applicable
Control field:
0 through 26: column data type
227: constraint name
255: index name
Xe$Offset
USMALLINT
not applicable
Xe$Size
USMALLINT
not applicable
C-6
Table C-6
Column Name
Type
Size
Case Insensitive
Description
Xe$Dec
UTINYINT
not applicable
Xe$Flags
USMALLINT
not applicable
Flags word.
Bit 0 is the case flag for string data types.
If bit 0 = 1, the field is case insensitive.
If bit 2 = 1, the field allows null values.
Bit 3 of Xe$flag is used to differentiate a
Pervasive.SQL v7 1-byte TINYINT
(B_TYPE_INTEGER unsigned) from SRDE's
1-byte TINYINT (B_TYPE_INTEGER, but
signed).
If bit 3 = 1 and Xe$datatype = 1 and Xe$size
=1, then it means that TINYINT column is
created by the SRDE and is a signed 1-byte
TINYINT.
If bit 3 = 0 and Xe$datatype = 1 and xe$size =
1 then it means that TINYINT column is
created by the legacy SQL engine and is an
unsigned 1-byte TINYINT.
If bit 12 = 1, the field is interpreted as BINARY.
If bit 13 = 1, the field is interpreted as
DECIMAL with even-byte precision.
C-7
System Tables
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xe$Id
No
not applicable
No
Xe$File
Yes
not applicable
No
Xe$Name
Yes
Yes
No
Xe$File
No
not applicable
Yes
Xe$Name
No
Yes
No
Xe$File
Yes
not applicable
Yes
Xe$Offset
Yes
not applicable
Yes
Xe$Dec
Yes
not applicable
No
X$File
The X$File system table is associated with the file FILE.DDF. For
each table defined in the database, X$File contains the table name,
the location of the associated table, and a unique internal ID number
that Pervasive PSQL assigns. The structure of X$File is as follows:
Table C-8
Column Name
Type
Size
Case Insensitive
Description
Xf$Id
USMALLINT
not applicable
Xf$Name
CHAR
20
Yes
Table name.
Xf$Loc
CHAR
64
No
Xf$Flags
UTINYINT
not applicable
Xf$Reserved
CHAR
10
No
Reserved.
C-8
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xf$Id
No
not applicable
No
Xf$Name
No
Yes
No
X$Index
The X$Index system table is associated with the file INDEX.DDF.
X$Index contains information about all the indexes defined on the
tables in the database. The structure of X$Index is as follows:
Table C-10
Column Name
Type
Size
Case Insensitive
Description
Xi$File
USMALLINT
not applicable
Xi$Field
USMALLINT
not applicable
Xi$Number
USMALLINT
not applicable
Xi$Part
USMALLINT
not applicable
Xi$Flags
USMALLINT
not applicable
Bit
Position
Decimal
Equivalent
Description
Index is modifiable.
C-9
System Tables
Table C-11
Bit
Position
Decimal
Equivalent
Description
Null values are not indexed (refers to Btrieve NULLs, not SQL true NULLS).
16
32
Index is case-insensitive.
64
128
Index is a named index if bit 0 is 0. If bit 0 is 1 and bit 7 is 1, the index uses the
repeating duplicates key method. If bit 0 is 1 and bit 7 is 0, the index uses the
linked duplicates key method. See also LINKDUP on page 3-88. For a detailed
discussion of linked duplicates method and repeating duplicates method, see
Methods for Handling Duplicate Keys on page 13-14 in Advanced Operations
Guide.)
256
512
Index is partial.
13
8192
14
16384
The value in the Xi$Flags column for a particular index is the sum of
the decimal values that correspond to that indexs attributes. Three
indexes are defined for the X$Index table, as follows:
Table C-12
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xi$File
Yes
not applicable
No
Xi$Field
Yes
not applicable
No
Xi$File
No
not applicable
Yes
Xi$Number
No
not applicable
Yes
Xi$Part
No
not applicable
No
C-10
X$Proc
The X$Proc system table is associated with the file PROC.DDF.
X$Proc contains the compiled structure information for every stored
procedure defined. The structure of X$Proc is as follows:
Table C-13
Column Name
Type
Size
Case Insensitive
Description
Xp$Name
CHAR
30
Yes
Xp$Ver
UTINYINT
not applicable
Xp$Id
USMALLINT
not applicable
Xp$Flags
UTINYINT
not applicable
Xp$Misc
LONGVARCHAR
(LVAR)
<=990
not applicable
C-11
System Tables
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xp$Name
No
Yes
Yes
Xp$Id
No
not applicable
No
Column Name
Type
Size
Case Insensitive
Description
Xr$PId
USMALLINT
not applicable
Xr$Index
USMALLINT
not applicable
Xr$FId
USMALLINT
not applicable
Xr$FIndex
USMALLINT
not applicable
Xr$Name
CHAR
20
Yes
Xr$UpdateRule
UTINYINT
not applicable
1 for restrict.
Xr$DeleteRule
UTINYINT
not applicable
Xr$Reserved
CHAR
30
No
Reserved.
C-12
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xr$PId
Yes
not applicable
No
Xr$FId
Yes
not applicable
No
Xr$Name
No
Yes
No
Xr$Pld
No
not applicable
Yes
Xr$Name
No
Yes
No
Xr$Fld
No
not applicable
Yes
Xr$Name
No
Yes
No
X$Rights
The X$Rights system table is associated with the file RIGHTS.DDF.
X$Rights contains access rights information for each user. Pervasive
PSQL uses this table only when you enable the security option. The
structure of X$Rights is as follows:
Table C-17
Column Name
Type
Size
Case Insensitive
Description
Xr$User
USMALLINT
not applicable
User ID
Xr$Table
USMALLINT
not applicable
Table ID
Xr$Column
USMALLINT
not applicable
Column ID
Xr$Rights
UTINYINT
not applicable
C-13
System Tables
Hex Value
Decimal Equivalent
Description
Reorganization in progress.
0x90
144
0xA0
160
0x40
64
0x82
130
0x84
132
0x88
136
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xr$User
Yes
not applicable
No
Xr$User
No
not applicable
Yes
Xr$Table
No
not applicable
Yes
Xr$Column
No
not applicable
No
Xr$Table
Yes
not applicable
Yes
Xr$Column
Yes
not applicable
No
C-14
X$Trigger
The X$Trigger system table is associated with the file
TRIGGER.DDF. X$Trigger contains information about the triggers
defined for the database. The structure of X$Trigger is as follows:
Table C-20
Column Name
Type
Size
Case Insensitive
Description
Xt$Name
CHAR
30
Yes
Trigger name.
Xt$Version
USMALLINT
not applicable
Xt$File
USMALLINT
not applicable
Xt$Event
UNSIGNED
not applicable
Xt$ActionTime
UTINYINT
not applicable
Xt$ForEach
UTINYINT
not applicable
Xt$Order
USMALLINT
not applicable
Xt$Sequence
USMALLINT
not applicable
Xt$Misc
LONGVARCHAR
(LVAR)
<=4054
not applicable
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xt$Name
No
Yes
Yes
Xt$Sequence
No
not applicable
No
Xt$File
No
not applicable
Yes
Xt$Name
No
Yes
Yes
Xt$Sequence
No
not applicable
No
C-15
System Tables
Table C-21
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xt$File
Yes
not applicable
Yes
Xt$Event
Yes
not applicable
Yes
Xt$ActionTime
Yes
not applicable
Yes
Xt$ForEach
Yes
not applicable
Yes
Xt$Order
Yes
not applicable
Yes
Xt$Sequence
Yes
not applicable
No
Column Name
Type
Size
Case Insensitive
Description
Xu$Id
USMALLINT
not applicable
Xu$Name
CHAR
30
Yes
Xu$Password
CHAR
No
Xu$Flags
USMALLINT
not applicable
Note For any row in the X$User system table that describes a
C-16
how Pervasive PSQL interprets each bit position when the bit has the
binary value of 1. Bit position 0 is the rightmost bit in the integer.
Table C-23
Bit
Position
Decimal Equivalent
Description
Reserved.
Reserved.
Reserved.
Reserved.
16
Reserved.
32
Reserved.
64
128
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xu$Id
Yes
not applicable
No
Xu$Name
No
Yes
No
X$View
The X$View system table is associated with the file VIEW.DDF.
X$View contains view definitions, including information about
joined tables and the restriction conditions that define views. You
can query the X$View table to retrieve the names of the views that are
defined in the dictionary.
C-17
System Tables
The first column of the X$View table contains the view name; the
second and third columns describe the information found in the
LVAR column, Xv$Misc. The structure of X$View is as follows:
Table C-25
Column Name
Type
Size
Case Insensitive
Description
Xv$Name
CHAR
20
Yes
View name.
Xv$Ver
UTINYINT
not applicable
Xv$Id
UTINYINT
not applicable
Sequence number.
Xv$Misc
LONGVARCHAR
(LVAR)
<=2000
not applicable
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xv$Name
Yes
Yes
No
Xv$Name
No
Yes
Yes
Xv$Ver
No
not applicable
Yes
Xv$Id
No
not applicable
No
C-18
V2 Metadata
System Tables
Table C-27
X$Attrib
The X$Attrib system table is associated with the file PVATTRIB.DDF.
X$Attrib contains information about the column attributes of each
column in the database; there is an entry for each column attribute
you define. The structure of X$Attrib is as follows:
Column Name
Type
Size
Case Insensitive
Description
Xa$Id
UINTEGER
not applicable
Xa$Type
CHAR
No
Xa$ASize
USMALLINT
Not applicable
Xa$Attrs
LONGVARCHAR
(NOTE)
32,763
not applicable
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xa$Id
No
not applicable
Yes
Xa$Type
No
No
No
C-19
System Tables
X$Depend
The X$Depend system table is associated with the file
PVDEPEND.DDF. X$Depend contains information about trigger
dependencies for such objects as tables, views, and procedures. The
structure of X$Depend is as follows:
Table C-29
Column Name
Type
Size
Case Insensitive
Description
Xd$Trigger
CHAR
128
Yes
Xd$DependType
UTINYINT
not applicable
Xd$DependName
CHAR
Yes
1
128
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xd$Trigger
No
Yes
Yes
Xd$DependType
No
not applicable
No
Xd$DependType
Yes
not applicable
Yes
Xd$DependName
Yes
Yes
No
C-20
X$Field
The X$Field system table is associated with the file PVFIELD.DDF.
X$Field contains information about all the columns and named
indexes defined in the database. The structure of X$Field is as
follows:
Table C-31
Column Name
Type
Xe$Id
UINTEGER
Xe$File
UINTEGER
Xe$Name
CHAR
Xe$Datatype
UTINYINT
Xe$Offset
UINTEGER
Size
Case Insensitive
Description
not applicable
not applicable
Yes
not applicable
not applicable
128
UINTEGER
not applicable
C-21
System Tables
Table C-31
Column Name
Type
Size
Xe$Dec
USMALLINT
Xe$Flags
UINTEGER
Case Insensitive
Description
not applicable
not applicable
Flags word.
Bit 0 is the case flag for string data types.
If bit 0 = 1, the field is case insensitive.
If bit 2 = 1, the field allows null values.
Bit 3 of Xe$flag is used to differentiate a
Pervasive.SQL v7 1-byte TINYINT
(B_TYPE_INTEGER unsigned) from SRDE's
1-byte TINYINT (B_TYPE_INTEGER, but
signed).
If bit 3 = 1 and Xe$datatype = 1 and Xe$size
=1, then it means that TINYINT column is
created by the SRDE and is a signed 1-byte
TINYINT.
If bit 3 = 0 and Xe$datatype = 1 and xe$size =
1 then it means that TINYINT column is
created by the legacy SQL engine and is an
unsigned 1-byte TINYINT.
If bit 12 = 1, the field is interpreted as BINARY.
If bit 13 = 1, the field is interpreted as
DECIMAL with even-byte precision.
C-22
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xe$Id
No
not applicable
No
Xe$File
Yes
not applicable
No
Xe$Name
Yes
Yes
No
Xe$File
No
not applicable
Yes
Xe$Name
No
Yes
No
Xe$File
Yes
not applicable
Yes
Xe$Offset
Yes
not applicable
Yes
Xe$Dec
Yes
not applicable
No
X$File
The X$File system table is associated with the file PVFILE.DDF. For
each table defined in the database, X$File contains the table name,
the location of the associated table, and a unique internal ID number
that Pervasive PSQL assigns. The structure of X$File is as follows:
Table C-33
Column Name
Type
Xf$Id
UINTEGER
Xf$Name
CHAR
Xf$Loc
CHAR
Xf$Flags
UINTEGER
Xf$Reserved
CHAR
Size
Case Insensitive
Description
not applicable
128
Yes
Table name.
250
No
not applicable
No
Reserved.
16
C-23
System Tables
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xf$Id
No
not applicable
No
Xf$Name
No
Yes
No
X$Index
The X$Index system table is associated with the file PVINDEX.DDF.
X$Index contains information about all the indexes defined on the
tables in the database. The structure of X$Index is as follows:
Table C-35
Column Name
Type
Size
Case Insensitive
Description
Xi$File
UINTEGER
not applicable
Xi$Field
UINTEGER
not applicable
Xi$Number
UINTEGER
not applicable
Xi$Part
UINTEGER
not applicable
Xi$Flags
UINTEGER
not applicable
C-24
The Xi$Flags column contains integer values that define the index
attributes. The following table describes how Pervasive PSQL
interprets each bit position when the bit has the binary value of 1. Bit
position 0 is the rightmost bit in the integer.
Table C-36
Bit
Position
Description
Index is modifiable.
Null values are not indexed (refers to Btrieve NULLs, not SQL true
NULLS).
16
32
Index is case-insensitive.
64
128
256
13
8,192
14
16,384
C-25
System Tables
The value in the Xi$Flags column for a particular index is the sum of
the decimal values that correspond to that indexs attributes. Three
indexes are defined for the X$Index table, as follows:
Table C-37
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xi$File
Yes
not applicable
No
Xi$Field
Yes
not applicable
No
Xi$File
No
not applicable
Yes
Xi$Number
No
not applicable
Yes
Xi$Part
No
not applicable
No
C-26
X$Proc
The X$Proc system table is associated with the file PVPROC.DDF.
X$Proc contains the compiled structure information for every stored
procedure defined. The structure of X$Proc is as follows:
Table C-38
Column Name
Type
Xp$Name
CHAR
Xp$Ver
UTINYINT
Xp$Id
Size
Case Insensitive
Description
Yes
not applicable
UINTEGER
not applicable
Xp$Flags
UINTEGER
not applicable
Xp$Trustee
INTEGER
not applicable
Xp$Sequence
USMALLINT
not applicable
128
LONGVARCHAR
(LVAR)
32,765
not applicable
C-27
System Tables
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xp$Name
Yes
Yes
Yes
Xp$Name
No
Yes
Yes
Xp$Ver
No
not applicable
Yes
Xp$Sequence
No
not applicable
No
Xp$Id
Yes
Yes
No
Xp$Id
No
not applicable
Yes
Xp$sequence
No
not applicable
No
X$Relate
The X$Relate system table is associated with the file
PVRELATE.DDF. X$Relate contains information about the
referential integrity (RI) constraints defined on the database.
X$Relate is automatically created when the first foreign key is
created, since this results in a relationship being defined.
The structure of X$Relate is as follows:
Table C-40
Column Name
Type
Xr$PId
UINTEGER
Xr$Index
Case Insensitive
Description
not applicable
UINTEGER
not applicable
Xr$FId
UINTEGER
not applicable
Xr$FIndex
UINTEGER
not applicable
Xr$Name
CHAR
Yes
Xr$UpdateRule
UTINYINT
not applicable
1 for restrict.
Xr$DeleteRule
UTINYINT
not applicable
Xr$Reserved
CHAR
No
Reserved.
C-28
Size
128
250
Index
Number
Segment
Number
Column Name
Duplicates
Modifiable
Case Insensitive
Segmented
Xr$PId
Yes
No
not applicable
No
Xr$FId
Yes
No
not applicable
No
Xr$Name
No
No
Yes
No
Xr$Pld
No
Yes
not applicable
Yes
Xr$Name
No
Yes
Yes
No
Xr$Fld
No
Yes
not applicable
Yes
Xr$Name
No
Yes
Yes
No
X$Rights
The X$Rights system table is associated with the file
PVRIGHTS.DDF. X$Rights contains access rights information for
each user. Pervasive PSQL uses this table only when you enable the
security option. The structure of X$Rights is as follows:
Table C-42
Column Name
Type
Size
Case Insensitive
Description
Xr$User
UINTEGER
not applicable
User ID
Xr$Object
UINTEGER
not applicable
Xr$Type
UINTEGER
not applicable
Xr$Column
UINTEGER
not applicable
Column ID
Xr$Rights
UINTEGER
not applicable
C-29
System Tables
Hex Value
Decimal
Equivalent
Description
0x90
144
0xA0
160
0x40
64
0x82
130
0x84
132
0x88
136
0xC0
192
C-30
The value in Xr$Rights for a user with all rights assigned for a view
is represented as follows:
64 | 130 | 132 | 136 = 206
The value in Xr$Rights for a user with all rights assigned for a stored
procedure is represented as follows:
192 = 192
Three indexes are defined for the X$Rights table, as follows:
Table C-44
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xr$User
Yes
not applicable
No
Xr$User
No
not applicable
Yes
Xr$Object
No
not applicable
Yes
Xr$Type
No
not applicable
Yes
Xr$Column
No
not applicable
No
Xr$Object
Yes
not applicable
Yes
Xr$Type
Yes
not applicable
Yes
Xr$Column
Yes
not applicable
No
C-31
System Tables
X$Trigger
The X$Trigger system table is associated with the file PVTRIG.DDF.
X$Trigger contains information about the triggers defined for the
database. The structure of X$Trigger is as follows:
Table C-45
Column Name
Type
Xt$Name
CHAR
Xt$Version
UTINYINT
Xt$File
Size
Case Insensitive
Description
Yes
Trigger name.
not applicable
UINTEGER
not applicable
Xt$Event
UTINYINT
not applicable
Xt$ActionTime
UTINYINT
not applicable
Xt$ForEach
UTINYINT
not applicable
Xt$Order
USMALLINT
not applicable
Xt$Sequence
USMALLINT
not applicable
128
C-32
LONGVARCHAR
(LVAR)
4,054
not applicable
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xt$Name
No
Yes
Yes
Xt$Sequence
No
not applicable
No
Xt$Name
No
Yes
Yes
Xt$File
No
No
Yes
Xt$Sequence
No
not applicable
No
Xt$File
Yes
not applicable
Yes
Xt$Event
Yes
not applicable
Yes
Xt$ActionTime
Yes
not applicable
Yes
Xt$ForEach
Yes
not applicable
Yes
Xt$Order
Yes
not applicable
Yes
Xt$Sequence
Yes
not applicable
No
X$User
The X$User system table is associated with the file PVUSER.DDF.
X$User contains the name and password of each user and the name
of each user group. Pervasive PSQL uses this table only when you
enable the security option. The structure of X$User is as follows:
Table C-47
Column Name
Type
Xu$Id
UINTEGER
Xu$Name
CHAR
Xu$Password
CHAR
Xu$Flags
UINTEGER
Size
Case Insensitive
Description
not applicable
128
Yes
128
No
not applicable
C-33
System Tables
Note For any row in the X$User system table that describes a
Bit
Position
Decimal
Equivalent
Description
Reserved.
Reserved.
Reserved.
Reserved.
16
Reserved.
32
Reserved.
64
128
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xu$Id
Yes
not applicable
No
Xu$Name
No
Yes
No
C-34
X$View
The X$View system table is associated with the file PVVIEW.DDF.
X$View contains view definitions, including information about
joined tables and the restriction conditions that define views. You
can query the X$View table to retrieve the names of the views that are
defined in the dictionary.
The first column of the X$View table contains the view name; the
second and third columns describe the information found in the
LVAR column, Xv$Misc. The structure of X$View is as follows:
Table C-50
Column Name
Type
Xv$Name
CHAR
Xv$Version
UTINYINT
Xv$Id
Size
Case Insensitive
Description
Yes
View name.
not applicable
UINTEGER
not applicable
Xv$Trustee
INTEGER
not applicable
0 for a trusted view and -1 for a nontrusted view. See Trusted and Nontrusted Objects on page 3-154.
Xv$Sequence
USMALLINT
not applicable
128
LONGVARCHAR
(LVAR)
32,765
not applicable
C-35
System Tables
Index Number
Segment Number
Column Name
Duplicates
Case Insensitive
Segmented
Xv$Name
Yes
Yes
No
Xv$Name
No
Yes
Yes
Xv$Ver
No
not applicable
Yes
Xv$Sequence
No
not applicable
No
Xv$Id
Yes
not applicable
No
Xv$Id
No
not applicable
Yes
Xv$Sequence
No
not applicable
No
C-36
Appendix
D-1
Overview
The Pervasive PSQL relational interface includes support for
COBOL OCCURS constructs, partial REDEFINES, and variable
record layouts.
A partial REDEFINE redefines a portion of the data within a record
(such as a 05 level within a 01 level). A variable record layout is also
referred to as a REDEFINES because the entire record is being
redefined. To avoid confusion with terminology, this section refers to
partial REDEFINES and to variable record layouts.
No changes are required to your COBOL application to take
advantage of the SQL access.
You enable SQL access by describing the applications understanding
of data to the Pervasive PSQL relational interface. In developers
terms, you define the metadata to the relational interface.
Note that this section applies only to COBOL applications that
include OCCURS, partial REDEFINES, or variable record layouts.
Restrictions
D-2
Overview
SQL
Statements
Table D-1
The following table lists the use of SQL statements with data tables
created from OCCURS, partial REDEFINES, or variable record
layouts.
Statement
Use with
OCCURs and
partial
REDEFINES
Use with
Variable
Record
Layouts
Notes
ALTER TABLE
No
No
CREATE INDEX
No
No
CREATE INDEX IN
DICTIONARY
No
Yes
CREATE TRIGGER
No
No
DELETE
No
Yes
DROP TABLE
Yes
Yes
INSERT INTO
No
No
UPDATE
Yes
Yes
Yes
Yes
D-3
Components
Pervasive PSQL v10 installs the following components to provide
SQL access for COBOL applications.
Table D-2
Component
Purpose
Location1
w3cobolschemaexec100.dll
file_path\PSQL\bin
libpsqlcobolschemaexec100.so
cobolschemaexec.xsd
cobolschemaexec.log
cobolschemaexec.exe
Windows server:
file_path\PSQL\schemas
Window server:
file_path\PSQL\logs
file_path\PSQL\bin
Linux server:
/user/local/psql/schemas/
Linux server:
/usr/local/psql/logs/
Linux install:
/usr/local/psq/bin/
D-4
Components
Table D-2
Component
Purpose
Location1
SampleMainWithOccurs.xml
Linux install:
/usr/local/psql/samples/
cobolschemaexec
Linux install:
/usr/local/psql/samples/
cobolschemaexec
Linux install:
/usr/local/psql/samples/
cobolschemaexec
SampleMainWithRedefines.xml
SampleVariantRecord.xml
default locations of Pervasive PSQL files, see Where are the Pervasive PSQL v10 files installed? on
page 7-2 in Getting Started With Pervasive PSQL.
D-5
Step 1: Modify Pervasive PSQL v10 includes sample XML templates that you use to
define the layout of data as required by your COBOL application. See
the Sample
XML Templates Table D-2. In developers terms, you describe your metadata in the
XML files.
Step 2: Copy
the Data File
Specified in the
XML Template
Save the modified template with a path and file name of your
choosing.
Copy the data file(s) specified in the XML file to the data file location
of the database before you run Schema Executor. The database is the
one to which you need to add the tables.
For example, you want to add a table (specified in the XML as
mytable.mkd) to a database "test" that has its data files under
c:\data\test. Copy the data file mytable.mkd to c:\data\test before you
run Schema Executor.
Step 3: Run the Pervasive PSQL v10 includes a command line utility called the
Schema Executor, which is also referred to as SchemaExec.
Schema
Executor Utility Schema Executor performs the following actions:
D-6
D-7
Table D-3
Option
Meaning
XMLfilename
The file name of the XML schema that defines the layout of the data. Required option.
See Step 1: Modify the Sample XML Templates on page D-6.
databasename
The name of the Pervasive PSQL database accessed by your application. Required
option. If the database specified does not exist, the utility prompts for a path and file
name.
See also Creating a New Database with Schema Executor on page D-10.
-s servername
The name or IP address of the server running the Pervasive PSQL database engine. You
may use localhost as the name if running SchemaExec on the same machine as the
database engine. If servername is not specified, the local machine is assumed to be the
server.
-u login_id
The user name required to access a secure database. See Pervasive PSQL Security
on page 7-1 in Advanced Operations Guide for a discussion of the Pervasive PSQL
security models.
-p password
The password required to access a secure database. See Pervasive PSQL Security on
page 7-1 in Advanced Operations Guide for a discussion of the Pervasive PSQL security
models.
-i svr_loginid
The login name required to access the operating system on a remote machine. This
option is required if SchemaExec is processing an XML file located on a remote server.
-c svr_password
The password required to access the operating system on a remote machine. This option
is required if SchemaExec is processing an XML file located on a remote server.
-l log_file
Log file to use for messages produced during processing of the XML file.
If you execute SchemaExec on a machine running the Pervasive PSQL database engine,
a default log is created automatically. You do not need to use the -l log_file option. The
default log is named cobolschemaexec.log.
If you execute SchemaExec on a client machine (a machine not running the Pervasive
PSQL database engine), you can specify a log file for the client machine.
See Log Messages on page D-10.
-h or -?
D-8
cobolschemaexec
file_path\PSQL\samples\cobolschemaexec\test.xml mytest
D-9
D-10
Error Code
Description
CB001
Unknown error.
CB002
CB003
CB004
CB005
CB006
CB007
CB008
CB009
CB010
CB012
CB013
CB014
CB016
CB017
CB018
CB019
CB022
CB023
CB024
CB025
CB028
CB029
D-11
Table D-4
Step 4:
Optionally,
Deploy the
System Tables
D-12
Error Code
Description
CB050
CB051
CB052
CB057
CB099
Parser error
CB100
CB101
CB102
CB103
CB105
CB106
CB108
CB109
CB110
Additional
Notes
For example, you perform the query SELECT * FROM FIELD for the
tables created by the execution of Schema Executor on the sample
XML file file_path\PSQL\samples\cobolschemaexec\
SampleMainWithOccurs.xml.
D-13
D-14
Used For
<
>
&
"
'
D-15
D-16
Appendix
E-1
SQL Statement
Discussion
Sets the location and name of the query plan file. NULL
specifies not to create a query plan file. A single query plan
output file can contain plans resulting from multiple queries.
By default, Query Plan Viewer looks for a file name
extension of "qpf." You may use whatever file name
extension you want, or omit one.
Example: You want to create a query plan named
"select_salary" and store the query plan file in a directory
named "mydirectory" on drive D off of the root:
SET QRYPLANOUTPUT='d:\mydirectory\select_salary.qpf'
The database engine creates the query plan output file, so
the path must be a location on the machine where the
database engine is running. The path should not reference
client-side locations or client drive mappings.
E-2
Query Pane
The SQL query displays in the Query Pane. The Query Pane also
contains menu commands to open a query plan file and to navigate
to the desired query plan when two or more plans are open
concurrently.
Only one query plan can be viewed at a time but multiple plans can
be opened concurrently.
Plan Pane
E-3
Nodes
The following table summarizes the nodes.
Table E-2
Node Symbol
Node Meaning
Represents data coming from a table in the
database. The name displayed under the
rectangle is the name of the table. If present, the
name shown under the table indicates the index
used to retrieve data from the table. An asterisk to
the right of the index name indicates that the index
contains unique values.
Represents a row selection operation. The word in
parentheses can be either "Normal" or "Range:"
E-4
Table E-2
Node Symbol
Node Meaning
Performs a JOIN between two nodes. The value in
parentheses indicates the type of JOIN performed:
E-5
Node Details
Table
Filter
Subquery
Ordered temporary table
Detailed Information
Table
Name of table
Range information. Range information is used only when the base table is on
the right side of a JOIN and the retrieval of data from the table can be optimized
through the use of an index. Range information includes:
Value used to initiate range retrieval (the value normally comes from another
table and column) and the value to terminate retrieval
Initial operations to perform, such as greater than (GT), greater than or equal to
(GE), less than (LT), and so forth
Filter (Normal)
Filter (Range)
Subquery
Ordered temp table
Condition that must evaluate to TRUE to stop reading more records (GT, GE,
and so forth)
The Plan Pane also contains menu commands to view the plan at
different zoom levels and to display subqueries, if any.
E-6
Navigate to the location of the desired query plan file, click the
file then click Open.
E-7
Note that the title bar of the Query Pane informs you how many
query plans are open and which plan you are viewing. For
example, if you open three query plans, you might see something
similar to the following:
If you have more than one query plan open, use the View menu
commands to navigate among the plans:
Table
Filter
Subquery
Ordered temporary table
E-8
Creating
Example Query
Plans for
Comparison
E-9
Viewing the
Example Query
Plans
E-10
E-11
E-12
Index
Symbols
@@IDENTITY global variable 3-290
Example of 3-290
@@ROWCOUNT global variable 3-292
Example of 3-292
@@SESSIONID global variable 3-292
Example of 3-292
@@SPID global variable 3-293
Example of 3-293
A
ABS 5-6
ACOS 5-6
ADD 3-3
grammar supported 3-3
Aggregate functions
AVG 3-204
COUNT 3-204
MAX 3-204
MIN 3-204
SUM 3-204
DECIMAL precision and 3-207
ALL 3-4
grammar supported 3-4
ALTER (rename) 3-5
ALTER GROUP 3-8
ALTER TABLE 3-10
grammar supported 3-10
IN DICTIONARY keyword 3-12
use with COBOL D-3
USING keyword 3-14
WITH REPLACE keyword 3-16
ALTER USER 3-26
Alternate collating sequence
setting a default for SQL session 3-237
alter-option (grammar element defined) 3-10, 3-281
alter-option-list1 (grammar element defined) 3-10,
3-281
alter-option-list2 (grammar element defined) 3-10,
3-281
B
before-or-after (grammar element defined) 3-103
before-or-after SQL grammar element definition 3281
BEGIN
grammar supported 3-31
Index 1
Between-predicate
grammar supported 3-215
BFLOAT data type A-2, A-25
BFLOAT4 data type A-2
BFLOAT8 data type A-2
BIGINT data type A-3
BINARY data type A-3
0-padded if odd digits 3-298
default value not supported 3-168
notes about A-11
SELECT and 3-298
Binary Large Objects A-26
BIT data type A-4
BIT_LENGTH 5-2
Bitwise operators
See Operators
BLOB data type A-2, A-26
default value not supported 3-168
Bound databases
IN DICTIONARY not permitted 3-13, 3-63
Btrieve owner names See Owner names
Btrieve temporary file 3-295
C
Cache
cached_procedures setting 3-231
excluding stored procedures with DDL 3-233, 3247
excluding stored procedures with EXEC 3-233, 3247
excluding stored procedures with temporary
tables 3-233, 3-247
exclusions to caching stored procedures 3-233, 3247
procedures_cache setting 3-245
stored procedures 3-231, 3-245
Cached_procedures setting 3-231
Caching
cached_procedures setting 3-231
excluding stored procedures with DDL 3-233, 3247
excluding stored procedures with EXEC 3-233, 3247
excluding stored procedures with temporary
tables 3-233, 3-247
2 Index
CB057 D-12
CB099 D-12
CB100 D-12
CB101 D-12
CB102 D-12
CB103 D-12
CB105 D-12
CB106 D-12
CB108 D-12
CB109 D-12
CB110 D-12
CEILING 5-6
Changing
System Tables C-2
CHAR 5-2
CHAR column size 2-3
CHAR data type A-3
notes about A-11
CHAR_LENGTH 5-2
Character
escape for wildcard characters 3-181
translation
OEM to ANSI 3-304
CHARACTER_LENGTH 5-2
CLOB data type A-2, A-26
default value not supported 3-168
CLOSE 3-40
grammar supported 3-40
Closing
open tables 3-299
COALESCE 3-41, 5-17
grammar supported 3-41
COALESCE ( (grammar element defined) 3-41
COBOL
DBCobolNumeric setting A-31
Schema Executor D-4
example usage D-9
executing sample XML file D-13
log messages D-10
sign value for positive NUMERIC data types A31
SQL access for applications D-8
SQL enhanced access
components D-4
Schema Executor D-4
using D-6
Index 3
4 Index
Creating
groups 1-11
stored procedures 3-78
tables with legacy null support 3-259
user-defined functions 1-5
users and groups 3-152
views 1-9
CURDATE 5-9
CURRENCY data type A-2, A-27
Current Date
adding to an INSERT statement 3-167, 3-169
Current Time
adding to an INSERT statement 3-167, 3-169
CURRENT_DATE 5-9
CURRENT_TIME 5-9
CURRENT_TIME() 3-252
CURRENT_TIMESTAMP 5-9
Cursor
how to loop through 3-77
limits 3-79
type changed by TOP 3-223
cursor-name SQL grammar element definition 3282
CURTIME 5-9
CURTIME() 3-252
D
Data
long, inserting or updating 3-168
Data control statements 1-10
Data definition language
see DDL
Data definition statements 1-3
Data dictionaries
list of system tables C-2
Data files
binary compatible cross-platform 3-15, 3-85
replacing existing 3-16, 3-86
system table (X$File) C-8, C-23
Data manipulation
statements 1-5
Data Source Names
connection string keywords 2-7
clients 2-7
engine 2-8
Data type
AUTOINC A-2
AUTOINC(4) A-2
BFLOAT A-2
BFLOAT4 A-2
BFLOAT8 A-2
BIGINT A-3
BINARY A-3
BIT A-4
BLOB A-2
CHAR A-3
CLOB A-2
CURRENCY A-2
DATE A-2
DATETIME A-2
DECIMAL A-2
DOUBLE A-2
FLOAT(4) A-2
FLOAT(8) A-2
GUID A-2, A-29
IDENTITY A-2
INTEGER A-3
INTEGER(1) A-2
INTEGER(2) A-2
INTEGER(4) A-3
INTEGER(8) A-3
LONGVARBINARY A-2
LONGVARCHAR A-2
NUMERIC A-3
NUMERICSA A-3
NUMERICSTS A-3
REAL A-2
SMALLIDENTITY A-2
SMALLINT A-2
SQL_BINARY(-2) A-3
SQL_BIT(-7) A-4
SQL_CHAR(1) A-3
SQL_DATE(9) A-2
SQL_DECIMAL(3) A-2, A-3
SQL_DOUBLE(8) A-2
SQL_GUID(-11) A-2
SQL_INTEGER(4) A-2, A-3
SQL_LONGVARBINARY(-4) A-2
SQL_LONGVARCHAR(-1) A-2
SQL_NUMERIC(2) A-3
SQL_REAL(7) A-2
SQL_SMALLINT(5) A-2, A-3, A-4
Index 5
SQL_TIME(10) A-3
SQL_TIMESTAMP(11) A-3
SQL_TINYINT(-6) A-2, A-3
SQL_VARCHAR(12) A-4
STRING A-3
TIME A-3
TIMESTAMP A-3
TINYINT A-2
UBIGINT A-3
UINTEGER A-3
UNIQUEIDENTIFIER 3-118, 5-16, A-2, A-17
UNSIGNED(1) BINARY A-3
UNSIGNED(2) BINARY A-3
UNSIGNED(4) BINARY A-3
UNSIGNED(8) BINARY A-3
USMALLINT A-3
UTINYINT A-3
VARCHAR A-4
WSTRING A-3
WSZSTRING A-3
ZSTRING A-4
Data types
AUTOINCREMENT A-22
BFLOAT A-25
BLOB A-26
CLOB A-26
codes A-22
conversion A-2
converting to other types 5-20
CURRENCY A-27
DATE A-27
DECIMAL A-28
extended A-22
FLOAT A-28
INTEGER A-30
lengths and ranges A-5
limitations in stored procedures 3-70
limitations in triggers 3-104
limitations in user-defined functions 3-52
LOGICAL A-30
LSTRING A-30
MONEY A-31
not supported by relational interface A-4
NUMERIC A-31
NUMERICSA A-33
NUMERICSTS A-34
6 Index
REAL A-34
STRING A-26
supported A-2
that cannot be indexed 3-61
TIME A-34
TIMESTAMP A-35
UNSIGNED BINARY A-37
WSTRING A-37
WZSTRING A-37
ZSTRING A-37
DATABASE 5-16
Database
in which temporary tables are stored 3-97
object name
fully qualified restriction 2-6
Databases
joining multiple 3-219
data-type (grammar element defined) 3-80, 3-93
data-type SQL grammar element definition 3-282
data-type-name SQL grammar element definition 3282
Date
adding in INSERT statements 3-167
format supported 3-216, 3-296
functions supported 5-9
inserting current 3-167, 5-9
inserting or updating column values 3-216, 3296
literal format 3-216, 3-296
literal values 3-296
TIMESTAMP data type
why not to use A-36
Date arithmetic
grammar supported 3-218, 3-298
DATE data type A-2, A-27
DATEADD scalar function 5-10
DATEDIFF scalar function 5-11
Date-literal
grammar supported 3-216
DATENAME scalar function 5-12
DATEPART scalar function 5-12
DATETIME
truncating milliseconds with CONVERT 5-22
DATETIME data type A-2
Daylight savings, see Time
DAYNAME 5-13
DAYOFMONTH 5-13
DAYOFYEAR 5-13
DBCobolNumeric setting A-31
db-name SQL grammar element definition 3-282
DCOMPRESS 3-87
DDFs
changing data definitions without affecting data
files 3-63
DDL 1-3
creating index 1-4
creating stored procedure 1-4
creating table 1-3
creating trigger 1-4
creating user-defined function 1-5
creating view 1-4
deleting index 1-4
deleting stored procedure 1-4
deleting table 1-3
deleting trigger 1-4
deleting user-defined function 1-5
deleting view 1-4
exclusion to caching stored procedure 3-233, 3247
modifying table 1-3
DECIMAL data type A-2, A-28
precision of SUM() function result 3-207
Decimal separator
comma
display only 3-228, 3-235
comma as 3-228, 3-235, 3-300
DECLARE 3-113
grammar supported 3-113
DECLARE CURSOR 3-114
grammar supported 3-114
DEFAULT 3-116, 3-166
example of use in CREATE TABLE 3-87, 3-88
in UPDATE 3-269, 3-273
Default collating setting 3-237
Default values, see Values, default
default-value-expression (grammar element
defined) 3-80, 3-93
Definitions
index
Btrieve indexes and 3-14, 3-59, 3-86
DEGREES 5-6
DELETE 3-125
Index 7
Dynamic cursors
SET ROWCOUNT and 3-249
type changed by TOP 3-223
E
Enabling
security 1-10
END 3-140
grammar supported 3-140
Escape character 3-181
Exact-numeric-literal
grammar supported 3-216
Exceptions
to ODBC API support
SQLGetData 2-12
SQLGetInfo 2-12
SQLGetTypeInfo 2-12
SQLSpecialColumns 2-12
Exclusive OR bitwise operator 4-8
EXEC
exclusion to caching stored procedure 3-233, 3247
EXECUTE 3-141
exclusion to caching stored procedure 3-233, 3247
EXISTS 3-143
grammar supported 3-143
EXP 5-6
Expression
in stored procedures 3-289
subquery on left side of 3-208
expression (grammar element defined) 3-203
expression-or-subquery (grammar element defined)
3-203
expression-or-subquery SQL grammar element
definition 3-282
Expressions as Default Values for Date-Time
Columns 3-121
Supported Data Types and Constraints 3-119
Usage Context 3-122
Extended data types A-22
EXTRACT 5-13
F
FETCH 3-145
grammar supported 3-145
8 Index
string 5-2
system 5-16
time
inserting current 5-9
inserting value 5-9
G
Global variables 3-290
@@IDENTITY 3-290
@@ROWCOUNT 3-292
@@SESSIONID 3-292
@@SPID 3-293
Grammar Element Definitions 3-281
Grammar element definitions
alter-option 3-10, 3-281
alter-option-list1 3-10, 3-281
alter-option-list2 3-10, 3-281
alter-options 3-10, 3-281
before-or-after 3-103
CASE 3-34
case_value_expression 3-204
COALESCE ( 3-41
col-constraint 3-81, 3-94
collation-name 3-82, 3-94
column-constraint 3-81, 3-94
column-definition 3-80, 3-93
column-name 3-80, 3-93
comparison-operator 3-203
constraint-name 3-81, 3-94
data-type 3-80, 3-93
default-value-expression 3-80, 3-93
expression 3-201, 3-203
expression-or-subquery 3-203
fetch-orientation 3-68
ins-upd-del 3-103
join-definition 3-203
join-type 3-203
literal 3-81, 3-94
order-by-expression 3-108, 3-202
outer-join-definition 3-202
outer-join-type 3-202
parameter 3-66
parameter-type 3-66
parameter-type-name 3-66
predicate 3-203
procedure-name 3-66
proc-expr 3-66
proc-search-condition 3-68
proc-stmt 3-66
query-specification 3-202
referencing-alias 3-103
referential-actions 3-81, 3-94
referential-delete-action 3-81, 3-94
referential-update-action 3-81, 3-94
scalar-function 3-204
search-condition 3-203
select-item 3-202
select-list 3-201, 3-202
set-function 3-204
sqlstate-value 3-68
subquery-expression 3-204
table-constraint 3-81, 3-94
table-constraint-definition 3-81, 3-94
table-element 3-80, 3-93
table-name 3-80, 3-93
table-reference 3-201, 3-202
top-clause 3-202
transaction-statement 3-67
trigger-name 3-103
value 3-203
values-clause 3-166
view-name 3-108
GRANT 3-149
creating a user with GRANT LOGIN 3-149
grammar supported 3-149
Granting
rights 1-11
Greater than (>) operator 3-202
Group
creating a 1-11
GROUP BY 3-160
grammar supported 3-160
with a HAVING clause 3-162
group-name SQL grammar element definition 3282
GUID data type A-2, A-29
H
HAVING 3-162
in a GROUP BY expression 3-162
HOUR 5-13
Index 9
I
Identifiers
delimited in SQL statements 2-19
IDENTITY data type A-2
IDENTITY global variable. See @@IDENTITY
IF 3-163, 5-17
grammar supported 3-163
nesting limit 3-163
IF (with SELECT)
grammar supported 3-218
IFNULL 5-17
IN 3-165
grammar supported 3-165
IN DICTIONARY keyword 3-12, 3-63, 3-84, 3-136
not permitted on bound databases 3-13, 3-63
Index
creating 1-4
data types that cannot be indexed 3-61
definitions, SQL
Btrieve indexes and 3-14, 3-59, 3-86
disjointed, definition of 3-64
dropping named 1-4
maximum indexed nullable columns 3-59
name
maximum length of 2-4
optimizations 7-12
Index.ddf 3-64
INDEX.DDF C-3
index-definition SQL grammar element definition
3-282
Indexes
existing Btrieve and relational definitions 3-14, 359, 3-86
existing used when possible 3-14, 3-59, 3-86
partial 3-61, 3-186
system tables
X$Field C-6, C-21
X$Index C-9, C-24
index-name SQL grammar element definition 3202, 3-283
index-segment-definition SQL grammar element
definition 3-282
Infinity
representation A-19
In-memory temporary file 3-295
In-predicate
10 Index
J
JOIN 3-173
grammar supported 3-173
Join
Cartesian 3-221
cross-database 3-219
LEFT OUTER 3-220
maximum tables in a 2-5
multi-database 3-219
RIGHT OUTER 3-220
TOP clause in a 3-223
two-way LEFT OUTER JOIN 3-175
join type (grammar element defined) 3-203
join-definition (grammar element defined) 3-203
join-definition SQL grammar element definition 3283
L
label-name SQL grammar element definition 3-283
LCASE 5-2
LEAVE 3-180
grammar supported 3-180
LEFT 5-2
timestamp 3-297
Locale
setting time zone 3-252
Locale-specific behavior
comma as decimal separator
data display 3-228, 3-235
data entry 3-300
LOCATE 5-3
LOG 5-6
LOG10 5-7
LOGICAL data type A-30
Logical functions supported 5-17
Long data
inserting or updating 3-168
limits when using 3-79
LONGVARBINARY
limitation A-12
limitations in INSERT statements A-12
notes about A-11
using SQLGetData A-12
LONGVARBINARY data type A-2
LONGVARCHAR
limitations A-12
limitations in INSERT statements A-12
limitations in UNION statements 3-266
notes about A-11
using SQLGetData A-12
LONGVARCHAR data type A-2
LOOP 3-183
grammar supported 3-183
LSTRING data type A-30
LTRIM 5-3
M
Master user 3-152
MAX aggregate function 3-204
Maximum
column name length 2-3
length of view name 3-108
Metadata
conversion utility 2-2
Schema Executor D-8
system tables for version 2 C-2
version 2 2-2
versions of 2-2
Index 11
Milliseconds
truncating from DATETIME 5-22
MIN aggregate function 3-204
MINUTE 5-13
MOD 5-7
Modifying
data
statements for 1-8
MONEY data type A-31
MONTH 5-13
MONTHNAME 5-13
N
Name
fully qualified name of database object 2-6
Named databases
and file names 3-14, 3-84
Names
maximum length 2-3
Nesting limits
IF 3-163
NEWID scalar function 5-16
Nodes
used in query plan viewer E-4
Non-correlated subquery 3-270
Non-trusted objects 3-153
NOT 3-184
grammar supported 3-184
NOT bitwise operator 4-5
NOT NULL
default values and 3-167
NOW 5-14
NULL 5-17
attempted insert into NOT NULL column with
default value 3-167
cannot make column nullable 3-17
inserted by UPDATE if subquery returns no rows
3-270
Null
support
creating tables with legacy 3-259
setting for table creation 3-258, 3-259
Nullable columns
default value for 3-167
maximum number of indexed 3-59
NULLIF 5-17
12 Index
O
Object name
fully qualified restriction 2-6
Occurs DDF C-3
Occurs.DDF C-3
OCTET_LENGTH 5-3
ODBC
API
exceptions 2-12
support 2-9
security 3-152
Support 2-9
Attribute 2-14
Descriptor Field 2-15
Interface 2-9
support 2-9
supported APIs 2-9
ODBC API
functions
supported 2-9
OEM to ANSI
character translation 3-304
connection string 3-304
ON DELETE 3-84
ON UPDATE 3-84
On-disk temporary file 3-295
ONLY
grammar supported 3-185
OPEN 3-185
Operators
bitwise 4-2
bitwise AND (&) 4-3
bitwise Exclusive OR (^) 4-8
bitwise NOT (~) 4-5
bitwise OR (|) 4-6
truth table for bitwise operations 4-9
greater than 3-202
less than 3-202
Optimizations
index usage 7-12
restriction 7-4
SQL Relational Database Engine 7-1
subquery on left side of expression 3-208
Optimizing queries E-1
OR bitwise operator 4-6
ORDER BY 3-109
in view 3-109
SET ROWCOUNT and 3-249
TOP and 3-223
order-by-expression (grammar element defined) 3108, 3-202
order-by-expression SQL grammar element
definition 3-283
outer-join-definition (grammar element defined) 3202
outer-join-definition SQL grammar element
definition 3-283
outer-join-type (grammar element defined) 3-202
outer-join-type SQL grammar element definition 3283
Owner names 3-153
in secured databases 1-10
specifying in SQL 3-240
P
Padding
in BINARY columns A-11
in CHAR columns A-11
in LONGVARBINARY columns A-11
in LONGVARCHAR columns A-11
in VARCHAR columns A-11
Page
compression 3-87
sizes
specifying with SQL 3-87
Page compression
with CREATE TABLE statement 3-87
PAGESIZE 3-87
parameter (grammar element defined) 3-66
Parameter List
number of arguments for stored procedures 2-3,
3-70
parameter SQL grammar element definition 3-283
Index 13
Precedence
TOP vs. SET ROWCOUNT 3-223, 3-249
Precision
SUM result on DECIMAL data 3-207
precision SQL grammar element definition 3-283
Predicate
in stored procedures 3-288
predicate (grammar element defined) 3-203
predicate SQL grammar element definition 3-284
PRIMARY KEY 3-187
cannot ALTER column 3-17
grammar supported 3-187
PRINT 3-189
grammar supported 3-189
PROC.DDF C-3
Procedure
cached_procedures setting 3-231
caching of stored procedure 3-231, 3-245
exclusions to caching of stored procedure 3-233,
3-247
procedures_cache setting 3-245
procedure-name (grammar element defined) 3-66
procedure-name SQL grammar element definition
3-285
Procedures
creating 3-78
Procedures_cache setting 3-245
proc-expr (grammar element defined) 3-66
proc-expr SQL grammar element definition 3-284
proc-search-condition (grammar element defined)
3-68
proc-search-condition SQL grammar element
definition 3-284
proc-stmt (grammar element defined) 3-66
proc-stmt SQL grammar element definition 3-284
psp_column_attributes 6-6
psp_column_rights 6-9
psp_columns 6-3
psp_fkeys 6-13
psp_groups 6-15
psp_help_sp 6-17
psp_help_trigger 6-19
psp_help_udf 6-21
psp_help_view 6-23
psp_indexes 6-25
psp_pkeys 6-28
14 Index
psp_stored_procedures 6-33
psp_table_rights 6-39
psp_tables 6-36
psp_triggers 6-41
psp_udfs 6-43
psp_users 6-45
psp_view_rights 6-29, 6-47
psp_views 6-50
PUBLIC 3-190
grammar supported 3-190
public-or-user-group-name SQL grammar element
definition 3-285
Push down filter
See table filter
PVATTRIB.DDF C-3
PVDEPEND.DDF C-3
PVFIELD.DDF C-3
PVFILE.DDF C-3
PVINDEX.DDF C-3
PVPROC.DDF C-3
PVRELATE.DDF C-3
PVRIGHTS.DDF C-3
PVTRIG.DDF C-3
PVUSER.DDF C-3
PVVIEW.DDF C-3
Q
QUARTER 5-14
Queries
examining query plans E-1
optimizing E-1
settings for query plans E-2
Query
examining query plans E-1
optimizing E-1
Query pane
query plan viewer E-3
Query plan
nodes in query plan viewer E-4
outputfile E-2
settings for E-2
Query plan viewer E-1
how to start E-7
nodes E-4
panes E-3
settings E-2
R
RADIANS 5-7
RAND 5-7
Ranges
data types A-5
REAL data type A-2, A-34
Real Infinity
representation A-19
Record
compression 3-87
referencing-alias (grammar element defined) 3-103
referencing-alias SQL grammar element definition
3-285
Referential integrity
delete rules 3-84
update rules 3-84
X$Relate system table C-12, C-28
referential-actions (grammar element defined) 3-81,
3-94
referential-actions SQL grammar element definition
3-286
referential-delete-action (grammar element defined)
3-81, 3-94
referential-delete-action SQL grammar element
definition 3-286
referential-update-action (grammar element
defined) 3-81, 3-94
referential-update-action SQL grammar element
definition 3-286
Regional settings
comma as decimal separator
data display 3-228, 3-235
data entry 3-300
RELATE.DDF C-3
Relational index definitions
Index 15
CONVERT B-2
COUNT B-2
CREATE B-2
CREATESP B-2
CREATETAB B-2
CREATEVIEW B-2
CROSS B-2
CS B-2
CURDATE B-2
CURRENT B-2
CURSOR B-2
CURTIME B-2
DATABASE B-3
DCOMPRESS B-3
DDF B-3
DECIMALSEPARATORCOMMA B-3
DECLARE B-3
DEFAULT B-3
DEFAULTCOLLATE B-3
DELETE B-3
DENY B-3
DESC B-3
DIAGNOSTICS B-3
DICTIONARY B-3
DISTINCT B-3
DO B-3
DROP B-3
DSN B-3
EACH B-3
ELSE B-3
END B-3
ENFORCED B-3
EX B-3
EXCLUSIVE B-3
EXEC B-3
EXECUTE B-3
EXISTING B-3
EXISTS B-3
FETCH B-3
FN B-3
FOR B-3
FOREIGN B-3
FROM B-3
FULL B-3
FUNCTION B-3
GRANT B-3
16 Index
GROUP B-3
HANDLER B-3
HAVING B-3
IF B-4
IN B-4
INDEX B-4
INNER B-4
INOUT B-4
INSERT B-4
INTEGRITY B-4
INTERNAL B-4
INTO B-4
IS B-4
ISOLATION B-4
JOIN B-4
KEY B-4
LEAVE B-4
LEFT B-4
LEGACYOWNERNAME B-4
LEVEL B-4
LIKE B-4
LOGIN B-4
LOOP B-4
MAX B-4
MIN B-4
MODE B-4
MODIFIABLE B-4
MODIFY B-4
NEW B-4
NEXT B-4
NO B-4
NORMAL B-4
NOT B-4
NOW B-4
NULL B-4
OF B-5
OFF B-5
OLD B-5
ON B-5
ONLY B-5
OPEN B-5
OR B-5
ORDER B-5
OUT B-5
OUTER B-5
OWNER B-5
PAGESIZE B-5
PARTIAL B-5
PRIMARY B-5
PRINT B-5
PROCEDURE B-5
PUBLIC B-5
READ B-5
REFERENCES B-5
REFERENCING B-5
RELATIONAL B-5
RELEASE B-5
REPEAT B-5
REPEATABLE B-5
REPLACE B-5
RESTRICT B-5
RETURN B-5
RETURNS B-5
REVOKE B-5
RIGHT B-5
ROLLBACK B-5
ROW B-5
ROWCOUNT B-5
SAVEPOINT B-5
SECURITY B-5
SELECT B-5
SERIALIZABLE B-5
SET B-5
SIGNAL B-5
SIZE B-5
SQLSTATE B-5
SSP_EXPR B-5
SSP_PRED B-5
START B-5
SUM B-5
SVBEGIN B-5
SVEND B-5
T B-6
TABLE B-6
THEN B-6
TO B-6
TOP B-6
TRANSACTION B-6
TRIGGER B-6
TRIGGERSTAMPMISC B-6
TRUEBITCREATE B-6
TRUENULLCREATE B-6
TS B-6
UNCOMMITTED B-6
UNION B-6
UNIQUE B-6
UNIQUEIDENTIFER B-6
UNTIL B-6
UPDATE B-6
USER B-6
USING B-6
VALUES B-6
VIEW B-6
WHEN B-6
WHERE B-6
WHILE B-6
WITH B-6
WORK B-6
WRITE B-6
RESTRICT 3-193
grammar supported 3-193
ON DELETE 3-84
result SQL grammar element definition 3-286
Results
returning partial set 3-222, 3-249
Retrieving data
about 1-7
RETURNS
example of in CREATE PROCEDURE 3-73
REVOKE 3-194
grammar supported 3-194
Revoking rights 1-11
RI. See Referential integrity
RIGHT 5-3
Rights
granting 1-11
revoking 1-11
RIGHTS.DDF C-3
ROLLBACK 3-197
ROLLBACK WORK
grammar supported 3-197
rollback-statement SQL grammar element definition
3-286
ROUND 5-7
ROWCOUNT (SET) 3-249
ROWCOUNT global variable. See @@ROWCOUNT
Index 17
Rows
limiting number returned 3-222, 3-249
limits 2-5
Rowset size
specifying 3-249
RTRIM 5-3
S
SAVEPOINT 3-199
grammar supported 3-199
savepoint-name SQL grammar element definition 3286
Scalar functions
ABS 5-6
ACOS 5-6
ASCII 5-2
ASIN 5-6
ATAN 5-6
ATAN2 5-6
BIT_LENGTH 5-2
CAST 5-21
categories
conversion 5-20
date 5-9
numeric 5-6
string 5-2
system 5-16
time 5-9
CEILING 5-6
CHAR 5-2
CHAR_LENGTH 5-2
CHARACTER_LENGTH 5-2
COALESCE 5-17
CONCAT 5-2
CONVERT 5-21
truncating DATETIME milliseconds 5-22
COS 5-6
COT 5-6
CURDATE 5-9
CURRENT_DATE 5-9
CURRENT_TIME 5-9
CURRENT_TIMESTAMP 5-9
CURTIME 5-9
DATABASE 5-16
DATEADD 5-10
DATEDIFF 5-11
18 Index
DATENAME 5-12
DATEPART 5-12
DAYNAME 5-13
DAYOFMONTH 5-13
DAYOFYEAR 5-13
DEGREES 5-6
EXP 5-6
EXTRACT 5-13
FLOOR 5-6
HOUR 5-13
IF 5-17
IFNULL 5-17
ignore fractional seconds in TIMESTAMP A-35
ISNULL 5-17
LCASE or LOWER 5-2
LEFT 5-2
LENGTH 5-2
LOCATE 5-3
LOG 5-6
LOG10 5-7
LTRIM 5-3
MINUTE 5-13
MOD 5-7
MONTH 5-13
MONTHNAME 5-13
NEWID 5-16
NOW 5-14
NULL 5-17
NULLIF 5-17
OCTET_LENGTH 5-3
PI 5-7
POSITION 5-3
POWER 5-7
QUARTER 5-14
RADIANS 5-7
RAND 5-7
REPLACE 5-3
REPLICATE 5-3
RIGHT 5-3
ROUND 5-7
RTRIM 5-3
SECOND 5-14
SIGN 5-7
SIN 5-7
SPACE 5-3
SQRT 5-7
STUFF 5-3
SUBSTRING 5-3
TAN 5-7
TIMESTAMPADD 5-14
TIMESTAMPDIFF 5-14
TRUNCATE 5-7
UCASE or UPPER 5-3
USER 5-16
WEEK 5-14
YEAR 5-14
scalar-function (grammar element defined) 3-204
scalar-function SQL grammar element definition 3286
scale SQL grammar element definition 3-286
Schema Executor D-4, D-8
example usage D-9
executing sample XML file D-13
log messages D-10
table filters used with D-14
SchemaExec
See Schema Executor
search-condition (grammar element defined) 3-203
search-condition SQL grammar element definition
3-286
SECOND 5-14
Secured databases
with Btrieve Owner Names 1-10
Security
enabling and disabling 1-10
owner names 3-153, 3-240
password of Master user 3-152
relational 3-152
SET OWNER 3-240
setting 3-250
system tables
rights (X$Rights) C-13, C-29
users (X$User) C-16, C-33
SELECT 3-202
grammar supported 3-202
maximum number of columns 2-5
TOP clause 3-222
SELECT (with INTO)
grammar supported 3-201
SELECT (with into) 3-201
select-item (grammar element defined) 3-202
select-item SQL grammar element definition 3-286
Index 19
Single quote
matching data that contains a 3-181
Single quote, representing 2-4
Size
of data page, specifying 3-87
of objects for relational interface 2-2
SMALLIDENTITY data type A-2
SMALLINT data type A-2
Sort order in keys
string A-21
SPACE 5-3
Spacing
in BINARY columns A-11
in CHAR columns A-11
in LONGVARBINARY columns A-11
in LONGVARCHAR columns A-11
in VARCHAR columns A-11
Special characters 3-181
SPID global variable. See @@SPID
SQL
ADD 3-3
ALL 3-4
ALTER (rename) 3-5
ALTER GROUP 3-8
ALTER TABLE 3-10
ALTER USER 3-26
ANY 3-28
AS 3-29
CALL 3-32
CASCADE 3-33
CASE (expression) 3-34
CASE (string) 3-39
CLOSE 3-40
COALESCE 3-41
COMMIT 3-44
CREATE (temporary) TABLE 3-93
CREATE DATABASE 3-46
CREATE FUNCTION 3-51
CREATE GROUP 3-58
CREATE INDEX 3-59
CREATE PROCEDURE 3-66
CREATE TABLE 3-80
CREATE TRIGGER 3-103
CREATE USER 3-106
CREATE VIEW 3-108
DECLARE 3-113
20 Index
Index 21
referential-actions 3-286
referential-delete-action 3-286
referential-update-action 3-286
release-statement 3-286
result 3-286
rollback-statement 3-286
savepoint-name 3-286
scalar-function 3-286
scale 3-286
search-condition 3-286
select-item 3-286
select-list 3-286
set-function 3-286
sqlstate-value 3-286
table-constraint 3-286
table-constraint-definition 3-286
table-element 3-287
table-expression 3-287
table-name 3-287
table-privilege 3-287
table-reference 3-287
transaction-statement 3-287
trigger-name 3-287
user-group-name 3-287
user-name 3-287
user-password 3-287
value 3-287
value-list 3-288
values-clause 3-288
variable-name 3-288
view-name 3-288
SQL Grammar Elements 3-2
SQL Relational Database Engine
optimizations 7-1
performance 7-1
restriction optimization 7-4
temporary files, location 3-294
SQL session
setting a collating default 3-237
SQL_BINARY(-2) data type A-3
SQL_BIT(-7) data type A-4
SQL_CHAR(1) data type A-3
SQL_DATE(9) data type A-2
SQL_DECIMAL(3) data type A-2, A-3
SQL_DOUBLE(8) data type A-2
SQL_FLOAT A-4
22 Index
SQLGetDescRec 2-11
SQLGetDiagField 2-11
SQLGetDiagRec 2-11
SQLGetEnvAttr 2-11
SQLGetFunctions 2-11
SQLGetInfo 2-11, 2-13
exception to ODBC API 2-12
SQLGetStmtAttr 2-11
SQLGetTypeInfo 2-11, 2-12
exception to ODBC API 2-12
SQLMoreResults 2-11, 2-12
SQLNativeSql 2-11
SQLNumParams 2-11
SQLNumResultCols 2-11
SQLParamData 2-11
SQLPrepare 2-11
SQLPrimaryKeys 2-11
SQLProcedureColumns 2-11
SQLProcedures 2-11
SQLPutData 2-11
SQLRowCount 2-11
SQLSetConnectAttr 2-11
SQLSetCursorName 2-11
SQLSetDescField 2-11
SQLSetDescRec 2-11
SQLSetEnvAttr 2-11
SQLSetPos 2-11
SQLSetStmtAttr 2-12
SQLSpecialColumns 2-12
exception to ODBC API 2-12
SQLSTATE 3-263
grammar supported 3-263
sqlstate-value (grammar element defined) 3-68
sqlstate-value SQL grammar element definition 3286
SQLStatistics 2-12
SQLTablePrivileges 2-12
SQLTables 2-12
SQRT 5-7
START TRANSACTION 3-264
grammar supported 3-264
Statement delimiter, changing 3-2
Statements
maximum per connection 2-5
Static cursor
type changed by TOP 3-223
Stored procedure
cached_procedures setting 3-231
caching of 3-231, 3-245
exclusion to caching of temporary table 3-233, 3247
exclusion to caching with DDL 3-233, 3-247
exclusion to caching with EXEC 3-233, 3-247
exclusions to caching of 3-233, 3-247
procedures_cache setting 3-245
Stored procedures
calling 1-9
creating 1-4, 1-5
data type limitations 3-70
dropping 1-4, 1-5, 3-135
executing 1-9
expressions 3-289
limits 3-78
max. number of columns 2-3, 3-70
number of arguments in a parameter list 2-3,
3-70
total size 2-5, 3-70
permissions on 3-153
predicates 3-288
system table (X$Proc) C-11, C-27
use of variables as select items 3-69
using 3-78
String
functions supported 5-2
literal values 3-296
Maximum size of quoted string in SQL statement
2-5
STRING data type A-3, A-26
Structured Query Language. See SQL
STUFF 5-3
Subquery
correlated 3-208, 3-270
eliminating duplicate rows with DISTINCT 3274
grammar supported 3-207
improved performance of 3-208
non-correlated 3-270
subquery-expression (grammar element defined) 3204
SUBSTRING 5-3
SUM aggregate function 3-204
and precision of DECIMAL type 3-207
Index 23
24 Index
T
Table
closing in an SQL statement 3-299
creating 1-3
creating with legacy null support 3-259
deleting 1-3
maximum number of columns 2-3
maximum number of rows 2-5
modifying 1-3
system tables C-1
updating system tables C-2
Table filter D-14
Table name
maximum length 2-5
table-constraint (grammar element defined) 3-81,
3-94
table-constraint SQL grammar element definition 3286
table-constraint-definition (grammar element
defined) 3-81, 3-94
table-constraint-definition SQL grammar element
definition 3-286
table-element (grammar element defined) 3-80, 393
table-element SQL grammar element definition 3287
table-expression SQL grammar element definition
3-287
table-name (grammar element defined) 3-80, 3-93
table-name SQL grammar element definition 3-287
Index 25
Timestamp
adding to an INSERT statement 3-167, 3-169
format supported 3-217, 3-297
inserting current 3-167
inserting or updating column values 3-217, 3297
literal format 3-217, 3-297
literal values 3-297
TIMESTAMP data type A-3, A-35
inappropriate for many purposes A-36
interpretation of literal values 3-253
TIMESTAMPADD 5-14
TIMESTAMPDIFF 5-14
Timestamp-literal
grammar supported 3-217, 3-297
TINYINT data type A-2
TMP environment variable
SQL Relational Database Engine
temporary files and 3-294
TOP
with SELECT 3-222
top-clause (grammar element defined) 3-202
Transactions
defining 1-8
transaction-statement (grammar element defined)
3-67
transaction-statement SQL grammar element
definition 3-287
TRANSLATIONDLL connection string 3-304
TRIGGER.DDF C-3
trigger-name (grammar element defined) 3-103
trigger-name SQL grammar element definition 3287
Triggers
calling 1-9
creating 1-4
data type limitations 3-104
dependencies
system table (X$Depend) C-5, C-20
dropping 1-4
executing 1-9
number of columns allowed 2-3, 3-70
system table (X$Trigger) C-15, C-32
TRUEBITCREATE 3-258
TRUENULLCREATE 3-259
TRUNCATE 5-7
26 Index
Truncate
milliseconds from DATETIME 5-22
Trusted objects 3-153
Truth table for bitwise operations 4-9
Type conversion 5-20
U
UBIGINT data type A-3
UCASE 5-3
UINTEGER data type A-3
Unicode data types A-37
Unicode key types A-22
UNION 3-266
grammar supported 3-266
limitations 3-266
UNIQUE 3-268
grammar supported 3-268
UNIQUEIDENTIFIER
data type A-17
UNIQUEIDENTIFIER data type 3-118, 5-16, A-2
Universal Time See Time
UNSIGNED BINARY data type A-37
UNSIGNED(1) BINARY data type A-3
UNSIGNED(2) BINARY data type A-3
UNSIGNED(4) BINARY data type A-3
UNSIGNED(8) BINARY data type A-3
UPDATE 3-269
fails if subquery returns multiple rows 3-271
grammar supported 3-269
use with COBOL D-3
Update
rule 3-84
UPDATE (positioned) 3-277
grammar supported 3-277
Updating
system tables C-2
UPPER 5-3
USER 3-279, 5-16
grammar supported 3-279
User
creating using CREATE USER 3-106
creating using GRANT LOGIN 3-149
Master 3-152
User name
maximum length 2-5
USER.DDF C-3
User-Defined Functions
creating 1-5
dropping 1-5
Invoking 3-54
limits 3-52
user-group-name SQL grammar element definition
3-287
user-name SQL grammar element definition 3-287
user-password SQL grammar element definition 3287
Users and user groups. See Security
USING keyword 3-14, 3-84
length of path name 3-14, 3-85
USMALLINT data type A-3
UTC Time See Time
Utilities
query plan viewer E-1
UTINYINT data type A-3
V
V1 metadata 2-2
system tables C-4
V2 metadata 2-2
system tables C-19
Valid Value Range
data types A-5
Value
default 3-166
value (grammar element defined) 3-203
value SQL grammar element definition 3-287
value-list SQL grammar element definition 3-288
Values
default
not supported for BLOB, CLOB, or BINARY
3-168
values-clause SQL grammar element definition 3288
VARCHAR data type A-4
notes about A-11
Variable
for adding current date 3-167
for adding current time 3-167
for adding timestamp 3-167
variable-name SQL grammar element definition 3288
Variables
W
WEEK 5-14
WHERE
clause 3-202
WHILE 3-280
grammar supported 3-280
Wildcard characters
any number of characters 3-181
escape character 3-181
single character 3-181
WITH REPLACE keyword 3-16, 3-86
Words to avoid B-7
ABSOLUTE B-7
ACTION B-7
ADD B-7
ALL B-7
ALLOCATE B-7
ALTER B-7
AND B-7
ANY B-7
ARE B-7
AS B-7
ASC B-7
ASSERTION B-7
AT B-7
Index 27
AUTHORIZATION B-7
AVG B-7
BEGIN B-7
BETWEEN B-7
BIT B-7
BIT_LENGTH B-7
BOTH B-7
BY B-7
CASCADE B-7
CASCADED B-7
CASE B-7
CAST B-7
CATALOG B-7
CHAR B-7
CHAR_LENGTH B-7
CHARACTER B-7
CHARACTER_LENGTH B-7
CHECK B-7
CLOSE B-7
COALESCE B-7
COLLATE B-7
COLLATION B-7
COLUMN B-7
COMMIT B-7
CONNECT B-7
CONNECTION B-7
CONSTRAINT B-7
CONSTRAINTS B-7
CONTINUE B-7
CONVERT B-7
CORRESPONDING B-7
COUNT B-7
CREATE B-7
CROSS B-7
CURRENT B-7
CURRENT_DATE B-8
CURRENT_TIME B-8
CURRENT_TIMESTAMP B-8
CURRENT_USER B-8
CURSOR B-8
DATE B-8
DAY B-8
DEALLOCATE B-8
DEC B-8
DECIMAL B-8
DECLARE B-8
28 Index
DEFAULT B-8
DEFERRABLE B-8
DEFERRED B-8
DELETE B-8
DESC B-8
DESCRIBE B-8
DESCRIPTOR B-8
DIAGNOSTICS B-8
DISCONNECT B-8
DISTINCT B-8
DOMAIN B-8
DOUBLE B-8
DROP B-8
ELSE B-8
END B-8
END-EXEC B-8
ESCAPE B-8
EXCEPT B-8
EXCEPTION B-8
EXEC B-8
EXECUTE B-8
EXISTS B-8
EXTERNAL B-8
EXTRACT B-8
FALSE B-8
FETCH B-8
FIRST B-8
FLOAT B-8
FOR B-8
FOREIGN B-8
FOUND B-8
FROM B-8
FULL B-8
FUNCTION B-8
GET B-8
GLOBAL B-8
GO B-8
GOTO B-8
GRANT B-8
GROUP B-8
HOUR B-8
IDENTITY B-8
IMMEDIATE B-8
IN B-8
INDICATOR B-8
INITIALLY B-8
INNER B-8
INPUT B-8
INSENSITIVE B-8
INSERT B-8
INT B-8
INTEGER B-8
INTERSECT B-8
INTERVAL B-8
INTO B-8
IS B-8
ISOLATION B-8
JOIN B-8
KEY B-8
LANGUAGE B-8
LAST B-8
LEADING B-8
LEFT B-8
LEVEL B-8
LIKE B-8
LOCAL B-8
LOWER B-9
MASK B-9
MATCH B-9
MAX B-9
MIN B-9
MINUTE B-9
MODULE B-9
MONTH B-9
NAMES B-9
NATIONAL B-9
NATURAL B-9
NCHAR B-9
NEXT B-9
NO B-9
NOT B-9
NULL B-9
NULLIF B-9
NUMERIC B-9
OCTET_LENGTH B-9
OF B-9
ON B-9
ONLY B-9
OPEN B-9
OPTION B-9
OR B-9
ORDER B-9
OUTER B-9
OUTPUT B-9
OVERLAPS B-9
PAD B-9
PARTIAL B-9
POSITION B-9
PRECISION B-9
PREPARE B-9
PRESERVE B-9
PRIMARY B-9
PRIOR B-9
PRIVILEGES B-9
PROCEDURE B-9
PUBLIC B-9
READ B-9
REAL B-9
REFERENCES B-9
RELATIVE B-9
RESTRICT B-9
REVOKE B-9
RIGHT B-9
ROLLBACK B-9
ROWS B-9
SCHEMA B-9
SCROLL B-9
SECOND B-9
SECTION B-9
SELECT B-9
SESSION B-9
SESSION_USER B-9
SET B-9
SIZE B-9
SMALLINT B-9
SOME B-9
SPACE B-9
SQL B-9
SQLCODE B-9
SQLERROR B-9
SQLSTATE B-9
SUBSTRING B-9
SUM B-9
SYSTEM_USER B-9
TABLE B-9
TEMPORARY B-9
THEN B-9
TIME B-9
Index 29
TIMESTAMP B-9
TIMEZONE_HOUR B-9
TIMEZONE_MINUTE B-9
TO B-9
TRAILING B-9
TRANSACTION B-9
TRANSLATE B-10
TRANSLATION B-10
TRIM B-10
TRUE B-10
UNION B-10
UNIQUE B-10
UNKNOWN B-10
UPDATE B-10
UPPER B-10
USAGE B-10
USER B-10
USING B-10
VALUE B-10
VALUES B-10
VARCHAR B-10
VARYING B-10
VIEW B-10
WHEN B-10
WHENEVER B-10
WHERE B-10
WITH B-10
WORK B-10
WRITE B-10
YEAR B-10
ZONE B-10
Words, reserved B-1
WSTRING data type A-3
WSTRING data type (Unicode) A-37
WSZSTRING data type A-3
WZSTRING data type (Unicode) A-37
X
X$Attrib C-3
X$Attrib system table C-4, C-19
X$Depend C-3
X$Depend system table C-5, C-20
X$Field C-3
X$Field system table C-6, C-21
X$File C-3
X$File system table C-8, C-23
30 Index
X$Index C-3
X$Index system table 3-64, C-9, C-24
X$Proc C-3
X$Proc system table C-11, C-27
X$Relate C-3
X$Relate system table C-12, C-28
X$Rights C-3
X$Rights system table C-13, C-29
X$Trigger C-3
X$Trigger system table C-15, C-32
X$User C-3
X$User system table C-16, C-33
X$View C-3
X$View system table C-17, C-35
XML
used with Schema Executor utility D-13
Y
YEAR 5-14
Z
Zone
setting time 3-252
ZSTRING data type A-4, A-37