Interbase Language Reference PDF
Interbase Language Reference PDF
2012 Embarcadero Technologies, Inc. Embarcadero, the Embarcadero Technologies logos, and all other
Embarcadero Technologies product or service names are trademarks or registered trademarks of
Embarcadero Technologies, Inc. All other trademarks are property of their respective owners.
Embarcadero Technologies, Inc. is a leading provider of award-winning tools for application developers
and database professionals so they can design systems right, build them faster and run them better,
regardless of their platform or programming language. Ninety of the Fortune 100 and an active community
of more than three million users worldwide rely on Embarcadero products to increase productivity, reduce
costs, simplify change management and compliance and accelerate innovation. The company's flagship
tools include: Embarcadero Change Manager, RAD Studio, DBArtisan, Delphi, ER/Studio,
JBuilder and Rapid SQL. Founded in 1993, Embarcadero is headquartered in San Francisco, with
offices located around the world. Embarcadero is online at www.embarcadero.com.
Contents
Tables . . . . . . . . . . . . . . . . . . . . . . . . . vii
COMMIT . . . . . . . . . . . . . . . .
CONNECT . . . . . . . . . . . . . . .
COUNT( ). . . . . . . . . . . . . . . .
CREATE DATABASE . . . . . . . . .
CREATE DOMAIN. . . . . . . . . . .
CREATE ENCRYPTION . . . . . . .
CREATE EXCEPTION . . . . . . . .
CREATE GENERATOR. . . . . . . .
CREATE INDEX . . . . . . . . . . . .
CREATE JOURNAL . . . . . . . . . .
CREATE JOURNAL ARCHIVE . . .
CREATE PROCEDURE . . . . . . .
CREATE ROLE . . . . . . . . . . . .
CREATE SHADOW . . . . . . . . . .
CREATE TABLE . . . . . . . . . . . .
CREATE TRIGGER . . . . . . . . . .
CREATE USER . . . . . . . . . . . .
CREATE VIEW . . . . . . . . . . . .
DECLARE CURSOR . . . . . . . . .
DECLARE CURSOR (BLOB) . . . .
DECLARE EXTERNAL FUNCTION.
DECLARE FILTER . . . . . . . . . .
DECLARE STATEMENT . . . . . . .
DECLARE TABLE . . . . . . . . . . .
DELETE . . . . . . . . . . . . . . . .
DESCRIBE . . . . . . . . . . . . . . .
DISCONNECT . . . . . . . . . . . . .
DROP DATABASE . . . . . . . . . .
DROP DOMAIN . . . . . . . . . . . .
DROP ENCRYPTION. . . . . . . . .
DROP EXCEPTION. . . . . . . . . .
DROP EXTERNAL FUNCTION . . .
DROP FILTER . . . . . . . . . . . . .
DROP GENERATOR . . . . . . . . .
DROP INDEX . . . . . . . . . . . . .
DROP JOURNAL . . . . . . . . . . .
DROP JOURNAL ARCHIVE . . . . .
DROP PROCEDURE . . . . . . . . .
DROP ROLE . . . . . . . . . . . . . .
DROP SHADOW . . . . . . . . . . .
DROP TABLE . . . . . . . . . . . . .
DROP TRIGGER . . . . . . . . . . .
DROP USER. . . . . . . . . . . . . .
DROP VIEW . . . . . . . . . . . . . .
END DECLARE SECTION . . . . . .
EVENT INIT . . . . . . . . . . . . . .
EVENT WAIT . . . . . . . . . . . . .
Chapter 1
Chapter 2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 2-1
. 2-1
. 2-2
. 2-2
. 2-2
. 2-2
. 2-2
. 2-2
. 2-3
. 2-4
. 2-5
. 2-6
. 2-7
. 2-7
. 2-8
. 2-8
. 2-9
. 2-9
. 2-10
. 2-13
. 2-14
. 2-15
. 2-16
. 2-17
. 2-23
. 2-24
. 2-26
. 2-26
. 2-27
. 2-28
. 2-29
. 2-30
. 2-31
. 2-31
iii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2-31
2-33
2-36
2-37
2-40
2-43
2-44
2-45
2-46
2-47
2-49
2-51
2-57
2-58
2-60
2-67
2-73
2-75
2-77
2-78
2-79
2-81
2-82
2-83
2-84
2-86
2-87
2-88
2-88
2-89
2-89
2-90
2-90
2-91
2-91
2-92
2-92
2-93
2-93
2-94
2-94
2-95
2-95
2-96
2-96
2-96
2-97
EXECUTE . . . . . . . . . .
EXECUTE IMMEDIATE . .
EXECUTE PROCEDURE .
EXTRACT( ). . . . . . . . .
FETCH. . . . . . . . . . . .
FETCH (BLOB) . . . . . . .
GEN_ID( ) . . . . . . . . . .
GRANT . . . . . . . . . . .
INSERT . . . . . . . . . . .
INSERT CURSOR (BLOB)
MAX( ) . . . . . . . . . . . .
MIN( ) . . . . . . . . . . . .
NULLIF( ) . . . . . . . . . .
OPEN . . . . . . . . . . . .
OPEN (BLOB) . . . . . . .
PREPARE . . . . . . . . . .
RELEASE SAVEPOINT . .
REVOKE . . . . . . . . . .
ROLLBACK . . . . . . . . .
SAVEPOINT. . . . . . . . .
SELECT . . . . . . . . . . .
SET DATABASE . . . . . .
SET GENERATOR . . . . .
SET NAMES . . . . . . . .
SET SQL DIALECT . . . .
SET STATISTICS. . . . . .
SET TRANSACTION. . . .
SHOW SQL DIALECT . . .
SUM( ) . . . . . . . . . . . .
UPDATE . . . . . . . . . . .
UPPER( ) . . . . . . . . . .
WHENEVER . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
FOR SELECTDO . . . . . . . . . .
IFTHEN ELSE . . . . . . . . . .
Input Parameters . . . . . . . . . . .
NEW Context Variables . . . . . . .
OLD Context Variables . . . . . . . .
Output Parameters . . . . . . . . . .
POST_EVENT. . . . . . . . . . . . .
SELECT . . . . . . . . . . . . . . . .
SUSPEND . . . . . . . . . . . . . . .
WHEN DO . . . . . . . . . . . . .
Handling Exceptions . . . . . . .
Handling SQL Errors . . . . . . .
Handling InterBase Error Codes .
WHILE DO . . . . . . . . . . . . .
. 2-98
. 2-99
2-100
2-102
2-102
2-104
2-105
2-106
2-109
2-111
2-112
2-113
2-113
2-114
2-115
2-115
2-117
2-117
2-120
2-121
2-121
2-127
2-129
2-130
2-131
2-131
2-132
2-135
2-135
2-136
2-138
2-138
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 5
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-10
3-11
3-11
3-12
3-13
3-14
3-15
3-15
3-16
3-18
3-19
3-19
3-19
3-20
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Keywords
Chapter 6
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Chapter 4
Chapter 3
Creating Triggers and Stored Procedures.
Statement Types Not Supported . . . . . .
Nomenclature Conventions . . . . . . . . .
Assignment Statement . . . . . . . . . . .
BEGIN END . . . . . . . . . . . . . . . .
Comment . . . . . . . . . . . . . . . . . . .
DECLARE VARIABLE . . . . . . . . . . . .
EXCEPTION . . . . . . . . . . . . . . . . .
EXECUTE PROCEDURE . . . . . . . . . .
EXECUTE STATEMENT . . . . . . . . . .
No rows or data returned . . . . . . . .
One Row of Data Returned . . . . . . .
Any Number of Data Rows Returned .
Requirements and Contraints . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3-1
3-2
3-2
3-3
3-3
3-4
3-5
3-6
3-6
3-8
3-8
3-8
3-9
3-9
Overview . . . . . . . . . . . . . . .
System Tables . . . . . . . . . . . .
RDB$CHARACTER_SETS . . . . .
RDB$CHECK_CONSTRAINTS . . .
RDB$COLLATIONS . . . . . . . .
RDB$DATABASE . . . . . . . . .
RDB$DEPENDENCIES . . . . . . .
RDB$ENCRYPTIONS . . . . . . .
RDB$EXCEPTIONS . . . . . . . .
RDB$FIELD_DIMENSIONS . . . .
RDB$FIELDS. . . . . . . . . . . .
RDB$FILES . . . . . . . . . . . .
RDB$FILTERS . . . . . . . . . . .
iv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 5-1
. 5-1
. 5-2
. 5-2
. 5-3
. 5-4
. 5-5
. 5-5
. 5-5
5-19
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 6-1
. 6-2
. 6-3
. 6-4
. 6-4
. 6-5
. 6-6
. 6-7
. 6-9
. 6-9
. 6-9
6-14
6-15
RDB$FORMATS . . . . . . . . . . .
RDB$FUNCTION_ARGUMENTS . .
RDB$FUNCTIONS . . . . . . . . .
RDB$GENERATORS . . . . . . . .
RDB$INDEX_SEGMENTS . . . . .
RDB$INDICES . . . . . . . . . . .
RDB$JOURNAL_ARCHIVES . . . .
RDB$LOG_FILES . . . . . . . . . .
RDB$PAGES . . . . . . . . . . . .
RDB$PROCEDURE_PARAMETERS .
RDB$PROCEDURES . . . . . . . .
RDB$REF_CONSTRAINTS . . . . .
RDB$RELATION_CONSTRAINTS .
RDB$RELATION_FIELDS . . . . . .
RDB$RELATIONS . . . . . . . . . .
RDB$ROLES . . . . . . . . . . . .
RDB$SECURITY_CLASSES . . . . .
RDB$TRANSACTIONS . . . . . . .
RDB$TRIGGER_MESSAGES . . . .
RDB$TRIGGERS . . . . . . . . . .
RDB$TYPES . . . . . . . . . . . .
RDB$USER_PRIVILEGES . . . . . .
RDB$USERS . . . . . . . . . . . .
RDB$VIEW_RELATIONS . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 6-15
. 6-16
. 6-17
. 6-17
. 6-18
. 6-18
. 6-20
. 6-21
. 6-21
. 6-21
. 6-22
. 6-23
. 6-23
. 6-24
. 6-26
. 6-29
. 6-30
. 6-30
. 6-31
. 6-31
. 6-33
. 6-33
. 6-34
. 6-35
. 6-36
. 6-36
. 6-38
. 6-40
. 6-40
TMP$POOLS . . . . . .
TMP$PROCEDURES . .
TMP$RELATIONS . . .
TMP$STATEMENTS . .
TMP$TRANSACTIONS
TMP$TRIGGERS . . . .
.
.
.
.
.
.
System Views . . . . . . .
CHECK_CONSTRAINTS .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
CONSTRAINTS_COLUMN_USAGE .
REFERENTIAL_CONSTRAINTS . . .
TABLE_CONSTRAINTS . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6-42
6-43
6-44
6-45
6-46
6-47
6-49
6-50
6-50
6-51
6-51
Chapter 7
vi
Tables
1.1
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
2.11
2.12
3.1
5.1
5.2
5.3
5.4
5.5
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.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.43
6.44
6.45
6.46
6.47
6.48
6.49
7.1
7.2
vii
RDB$INDEX_SEGMENTS . . . . . .
RDB$INDICES . . . . . . . . . . . .
RDB$JOURNAL_ARCHIVES . . . .
RDB$PAGES . . . . . . . . . . . . .
RDB$PROCEDURE_PARAMETERS
RDB$PROCEDURES . . . . . . . .
RDB$REF_CONSTRAINTS . . . . .
RDB$RELATION_CONSTRAINTS . .
RDB$RELATION_FIELDS . . . . . .
RDB$RELATIONS . . . . . . . . . .
RDB$ROLES . . . . . . . . . . . . .
RDB$SECURITY_CLASSES . . . .
RDB$TRANSACTIONS . . . . . . .
RDB$TRIGGER_MESSAGES . . . .
RDB$TRIGGERS . . . . . . . . . .
RDB$TYPES . . . . . . . . . . . . .
RDB$USER_PRIVILEGES . . . . . .
RDB$USERS. . . . . . . . . . . . .
RDB$VIEW_RELATIONS . . . . . .
TMP$ATTACHMENTS . . . . . . . .
. . . . 6-18
. . . . 6-19
. . . . 6-20
. . . . 6-21
. . . . 6-22
. . . . 6-22
. . . . 6-23
. . . . 6-24
. . . . 6-25
. . . . 6-27
. . . . 6-29
. . . . 6-30
. . . . 6-30
. . . . 6-31
. . . . 6-31
. . . . 6-33
. . . . 6-33
. . . . 6-34
. . . . 6-35
. . . . 6-36
TMP$DATABASE . . . . . . . . . . . . . 6-38
TMP$HEAPS . . . . . . . . . . . . . . . . . 6-40
TMP$POOL_BLOCKS . . . . . . . . . . . . 6-40
TMP$POOLS. . . . . . . . . . . . . . . . . 6-43
TMP$PROCEDURES . . . . . . . . . . . . 6-43
TMP$RELATIONS . . . . . . . . . . . . . . 6-44
TMP$STATEMENTS . . . . . . . . . . . . . 6-45
TMP$TRANSACTIONS . . . . . . . . . . . 6-46
TMP$TRIGGERS . . . . . . . . . . . . . . 6-47
CHECK_CONSTRAINTS . . . . . . . . . 6-50
CONSTRAINTS_COLUMN_USAGE . . 6-51
REFERENTIAL_CONSTRAINTS . . . . 6-51
TABLE_CONSTRAINTS . . . . . . . . . 6-51
Character sets and collation orders . . . . 7-2
Character sets corresponding to DOS code
pages . . . . . . . . . . . . . . . . . . . . . 7-6
viii
Chapter
Chapter 1
The InterBase Language Reference details the syntax and semantics of SQL and
Dynamic SQL (DSQL) statements for embedded applications programming and for
isql, the InterBase interactive SQL utility. It also describes additional language and
syntax that is specific to InterBase stored procedures and triggers.
1-1
Note
1-2
Chapter
Description
Chapter 4, Keywords
For a listing of functions provided in the InterBase UDF library, see the Working
with UDFs and Blob Filters chapter in the Developers Guide.
Language Reference
Chapter
Chapter 2
This chapter provides the syntax and usage for InterBase SQL language elements.
It includes the following topics:
SQL variants and dialects
Database object naming conventions
Lists of SQL statements and functions
A description of each InterBase datatype
An introduction to using SQLCODE to handle errors
How to use statement and function definitions
A reference entry for each SQL statement supported by InterBase
SQL Flavors
Although InterBase SQL follows the ISO/IEC 9075:1992 standard closely, there
are small differences. Differences also exist among the three major flavors of
InterBase SQL: embedded SQL, dynamic SQL (DSQL), and the procedure and
trigger language.
2-1
SQL Dialects
SQL Dialects
Starting with version 6, InterBase is closer to the ISO/IEC 9075:1992 standard
than previous versions in several ways. Some of those ways are incompatible with
earlier implementations of SQL. In the current InterBase, each client and database
has a SQL dialect: an indicator that instructs an InterBase server how to interpret
transition features: those features whose meanings have changed between
InterBase versions. See the Migration appendix in the Operations Guide for
information about using dialects and transition features.
Dialects
Dialect 1: transition features are interpreted as in InterBase version 5.6 and
earlier.
2-2
Language Reference
Transition Features
Double quote (): changed from a synonym for the single quote () to the
delimiter for an object name
Large exact numerics: DECIMAL and NUMERIC datatypes with precision greater
than 9 are stored at INT64 instead of DOUBLE PRECISION
DATE, TIME, and TIMESTAMP datatypes:
DATE has changed from a 64-bit quantity containing both date and time
information to a 32-bit quantity containing only date information
TIME is a 32-bit quantity containing only time information
TIMESTAMP is a 64-bit quantity containing both date and time information
(same as DATE in InterBase 5 and older)
2-3
Statement List
For more information about naming database objects with CREATE or DECLARE
statements, see the Language Reference.
Statement List
This chapter describes the following SQL statements:
2-4
ALTER DATABASE
ALTER DOMAIN
ALTER EXCEPTION
ALTER INDEX
ALTER PROCEDURE
ALTER TABLE
ALTER TRIGGER
ALTER USER
BASED ON
BEGIN DECLARE
SECTION
CASE
CLOSE
CLOSE (BLOB)
COALESCE( )
COMMIT
CONNECT
CREATE DATABASE
CREATE DOMAIN
CREATE ENCRYPTION
CREATE EXCEPTION
CREATE GENERATOR
CREATE INDEX
CREATE JOURNAL
CREATE JOURNAL
ARCHIVE
CREATE PROCEDURE
CREATE ROLE
CREATE SHADOW
CREATE TABLE
CREATE TRIGGER
CREATE USER
CREATE VIEW
DECLARE CURSOR
DECLARE EXTERNAL
FUNCTION
DECLARE FILTER
DECLARE STATEMENT
DECLARE TABLE
DELETE
DESCRIBE
DISCONNECT
DROP DATABASE
DROP DOMAIN
DROP ENCRYPTION
DROP EXCEPTION
DROP EXTERNAL
FUNCTION
DROP FILTER
DROP GENERATOR
DROP INDEX
DROP JOURNAL
DROP JOURNAL
ARCHIVE
DROP PROCEDURE
DROP ROLE
DROP SHADOW
DROP TABLE
DROP TRIGGER
DROP VIEW
DROP USER
EVENT WAIT
Language Reference
Function List
EXECUTE
EXECUTE IMMEDIATE
EXECUTE PROCEDURE
FETCH
FETCH (BLOB)
GRANT
INSERT
INSERT CURSOR
(BLOB)
NULLIF( )
OPEN
OPEN (BLOB)
PREPARE
RELEASE SAVEPOINT
REVOKE
ROLLBACK
SAVEPOINT
SELECT
SET DATABASE
SET GENERATOR
SET NAMES
SET STATISTICS
SET TRANSACTION
UPDATE
WHENEVER
Function List
The following table lists the SQL functions described in this chapter:
Table 2.1 SQL functions
Function
Type
Purpose
AVG()
Aggregate
CAST()
Conversion
COUNT()
Aggregate
EXTRACT()
Conversion
GEN_ID()
Numeric
MAX()
Aggregate
MIN()
Aggregate
SUM()
Aggregate
UPPER()
Conversion
2-5
Datatypes
Conversion functions transform datatypes, either converting them from one type to
another, or by changing the scale or precision of numeric values, or by converting
CHARACTER datatypes to all uppercase.
The numeric function, GEN_ID(), produces a system-generated number that can be
inserted into a column requiring a numeric datatype.
Datatypes
InterBase supports most SQL datatypes, a dynamically sizable datatype called a
Blob, and arrays of datatypes. It does not support arrays of Blobs. The following
table lists the datatypes available to SQL statements in InterBase:
Table 2.2 Datatypes supported by InterBase
Name
Size
Range/Precision
Description
BLOB
Variable
None
Blob segment size is limited to
64K
BOOLEAN
16 bits
TRUE
FALSE
UNKNOWN
CHAR(n)
n
characters
1 to 32,767 bytes
Character set character size
determines the maximum
number of characters that can fit
in 32K
DATE
32 bits,
signed1
DECIMAL (precision,
scale)
Variable
(16, 32, or
64 bits)
DOUBLE PRECISION
64 bits2
2-6
Language Reference
Exact Numerics
Size
Range/Precision
Description
FLOAT
32 bits
INTEGER
32 bits
2,147,483,648 to 2,147,483,647
NUMERIC (precision,
scale)
Variable
(16, 32, or
64 bits)
SMALLINT
16 bits
32,768 to 32,767
TIME
32 bits,
unsigned
0:00 AM to 23:59.9999 PM
ISC_TIME
TIMESTAMP
64 bits
VARCHAR (n)
n
characters
1 to 32,765 bytes
Character set character size
determines the maximum
number of characters that can fit
in 32K
1. InterBase version 5 had a DATE datatype that was 64 bits long and included both the date and time. InterBase version 6
and later recognizes that type if you have specified dialect 1; in dialect 3, that type is called TIMESTAMP.
2. Actual size of DOUBLE is platform-dependent. Most platforms support the 64-bit size.
Exact Numerics
All NUMERIC and DECIMAL datatypes are stored as exact numerics: 16, 32, or 64
bits, depending on the precision. NUMERIC and DECIMAL datatypes with precision
greater than 9 are referred to as large exact numerics.
If one operand is an approximate numeric, the result of any dyadic operation
(addition, subtraction, multiplication, division) is DOUBLE PRECISION.
Any value that can be stored in a DECIMAL(18,S) can also be specified as the
default value for a column or a domain.
2-7
Exact Numerics
Multiplication
If both operands are exact numeric, multiplying the operands produces an exact
numeric with a precision of 18 and a scale equal to the sum of the scales of the
operands. For example:
CREATE TABLE t1 (n1 NUMERIC(16,2), n2 NUMERIC(16,3));
INSERT INTO t1 VALUES (12.12, 123.123);
COMMIT;
the following query returns the integer 1492.25076 because n1 has a scale of 2
and n2 has a scale of 3. the sum of the scales is 5.
SELECT n1*n2 FROM t1
If one of the operands is approximate numeric (FLOAT, REAL, or DOUBLE
PRECISION), the result is DOUBLE PRECISION.
Division
If both operands are exact numeric, dividing the operands produces an exact
numeric with a precision of 18 and a scale equal to the sum of the scales of the
operands. If at least one operand of a division operator has an approximate
numeric type (FLOAT, REAL, or DOUBLE PRECISION), the result is DOUBLE
PRECISION.
For example, in the following table, division operations produce a variety of results:
CREATE TABLE t1 (i1 INTEGER), i2 INTEGER, n1 NUMERIC(16,2)
n2 NUMERIC(16,2));
INSERT INTO t1 VALUES (1, 3, 1.00, 3.00);
2-8
Language Reference
Error Handling
COMMIT;
The following query returns the integer 0 because each operand has a scale of 0,
so the sum of the scales is 0:
SELECT i1/i2 FROM t1
The following query returns the NUMERIC(18,2) value 0.33, because the sum of
the scales 0 (operand 1) and 2 (operand 2) is 2:
SELECT i1/n2 FROM t1
The following query returns the NUMERIC(18,4) value 0.3333, because the sum of
the two operand scales is 4:
SELECT n1/n2 FROM t1
In InterBase 5 and earlier, any of the above division operations would have
returned the DOUBLE PRECISION value 0.3333333333333333.
Error Handling
Every time an executable SQL statement is executed, the SQLCODE variable is set
to indicate its success or failure. No SQLCODE is generated for declarative
statements that are not executed, such as DECLARE CURSOR, DECLARE TABLE, and
DECLARE STATEMENT.
The following table lists values that are returned to SQLCODE:
Table 2.3 SQLCODE and message summary
SQLCODE
Message
Meaning
<0
SQLERROR
SUCCESS
Successful execution
+199
SQLWARNING
+100
NOT FOUND
2-9
For more information about error handling, see the Embedded SQL Guide.
Description
Title
Statement name
Definition
Syntax
Argument
Description
Examples
See also
Most statements can be used in SQL, DSQL, and isql. In many cases, the syntax
is nearly identical, except that embedded SQL statements must always be
preceded by the EXEC SQL keywords. EXEC SQL is omitted from syntax statements
for clarity.
In other cases there are small, but significant differences among SQL, DSQL, and
isql syntax. In these cases, separate syntax statements appear under the
statement heading.
ALTER DATABASE
Changes the characteristics of the current database. Available in gpre, DSQL, and
isql, but not in the trigger or stored procedure language.
Syntax
2-10
Language Reference
Description
SCHEMA
ENCRYPT key_name
DECRYPT key_name
SET NO FLUSH
INTERVAL
SET NO GROUP
COMMIT
2-11
Description
Argument
Description
SET NO LINGER
INTERBAL
SET RECLAIM
INTERVAL
SET NO RECLAIM
INTERVAL
SET SYSTEM
ENCRYPTION
PASSWORD
SET NO SYSTEM
ENCRYPTION
PASSWORD
Note
InterBase dynamically expands the last file in a database as needed. The maximum
size of the last file is system-dependent. You should be aware that specifying a
LENGTH for such files has no effect.
You cannot use ALTER DATABASE to split an existing database file. For example, if
your existing database is 80,000 pages long and you add a secondary file
STARTING AT 50000, InterBase starts the new database file at page 80,001.
Tip
2-12
To split an existing database file into smaller files, back it up and restore it. When
you restore a database, you are free to specify secondary file sizes at will, without
reference to the number and size of the original files.
Language Reference
Example
The following isql statement adds two secondary files to an existing database. The
command creates a secondary database file called employee2.ib that is 10,000
pages long and another called employee3.ib. InterBase starts using employee2.ib
only when the primary file reaches 10,000 pages.
ALTER DATABASE
ADD FILE 'employee2.ib'
STARTING AT PAGE 10001 LENGTH 10000
ADD FILE 'employee3.ib';
See also
See the Data Definition Guide for more information about multi-file databases and
the Operations Guide for more information about exclusive database access.
For detailed information on encryption and decryption, see the topics Encrypting
Data (page 13-9) and Decrypting Data (page 13-11) in the Data Definition
Guide.
ALTER DOMAIN
Changes a domain definition. Available in gpre, DSQL, and isql, but not in the
stored procedure or trigger language.
ALTER DOMAIN { name | old_name TO new_name }
SET DEFAULT {literal | NULL | USER}
| DROP DEFAULT
| ADD [CONSTRAINT] CHECK (dom_search_condition)
| DROP CONSTRAINT
| new_col_name
| TYPE datatype;
dom_search_condition =
VALUE operator val
| VALUE [NOT] BETWEEN val AND val
| VALUE [NOT] LIKE val [ESCAPE val]
| VALUE [NOT] IN (val [, val ])
| VALUE IS [NOT] NULL
| VALUE [NOT] CONTAINING val
| VALUE [NOT] STARTING [WITH] val
| (dom_search_condition)
| NOT dom_search_condition
| dom_search_condition OR dom_search_condition
| dom_search_condition AND dom_search_condition
operator = {= | < | > | <= | >= | !< | !> | <> | !=}
Important
2-13
Description
Argument
Description
name
SET DEFAULT
DROP DEFAULT
dom_search_condition
DROP CONSTRAINT
new_col_name
TYPE data_type
ALTER DOMAIN changes any aspect of an existing domain except its NOT NULL
setting. Changes made to a domain definition affect all column definitions based
on the domain that have not been overridden at the table level.
Note
To change the NOT NULL setting of a domain, drop the domain and recreate it with
the desired combination of features.
The TYPE clause of ALTER DOMAIN does not allow you to make datatype
conversions that could lead to data loss.
A domain can be altered by its creator, the SYSDBA user, and any users with
operating system root privileges.
Example
The following isql statements create a domain that must have a value > 1,000,
then alter it by setting a default of 9,999:
CREATE DOMAIN CUSTNO
AS INTEGER
CHECK (VALUE > 1000);
ALTER DOMAIN CUSTNO SET DEFAULT 9999;
See also
For a complete discussion of creating domains, and using them to create column
definitions, see the Data Definition Guide.
2-14
Language Reference
ALTER EXCEPTION
Changes the message associated with an existing exception. Available in DSQL
and isql but not the embedded language or stored procedure and trigger language.
Syntax
Description
Description
name
message
An exception can be altered by its creator, the SYSDBA user, and any users with
operating system root privileges.
Example
See also
For more information on creating, raising, and handling exceptions, see the Data
Definition Guide .
ALTER INDEX
Activates or deactivates an index. Available in embedded SQL, DSQL, and isql,
but not in the stored procedure or trigger language.
Syntax
Important
Description
name
ACTIVE
INACTIVE
2-15
Description
ALTER INDEX makes an inactive index available for use, or disables the use of an
active index. Deactivating an index is exactly like dropping it, except that the index
definition remains in the database. Activating an index creates a new index
structure.
Before inserting, updating, or deleting a large number of rows, deactivate a tables
indexes to avoid altering the index incrementally. When finished, reactivate the
index. A reasonable metric is that if you intend to add or delete more than 15% of
the rows in a table, or update an indexed column in more than 10% of the rows,
you should consider deactivating and reactivating the index.
If an index is in use, ALTER INDEX does not take effect until the index is no longer in
use.
ALTER INDEX fails and returns an error if the index is defined for a UNIQUE, PRIMARY
KEY, or FOREIGN KEY constraint. To alter such an index, use DROP INDEX to delete
the index, then recreate it with CREATE INDEX.
An index can be altered by its creator, the SYSDBA user, and any users with
operating system root privileges.
Note
Example
To add or drop index columns or keys, use DROP INDEX to delete the index, then
recreate it with CREATE INDEX.
The following isql statements deactivate and reactivate an index to rebuild it:
ALTER INDEX BUDGETX INACTIVE;
ALTER INDEX BUDGETX ACTIVE;
See also
ALTER PROCEDURE
Changes the definition of an existing stored procedure. Available in DSQL and isql
but not in the embedded language or in the stored procedures or triggers.
Syntax
2-16
Description
name
Language Reference
Description
Argument
Description
param datatype
procedure_body
The complete procedure header and body must be included in the ALTER
PROCEDURE statement. The syntax is exactly the same as CREATE PROCEDURE,
except CREATE is replaced by ALTER.
Important
Be careful about changing the type, number, and order of input and output
parameters to a procedure, because existing application code may assume the
procedure has its original format. Check for dependencies between procedures
before changing parameters. Should you change parameters and find that another
procedure can neither be altered to accept the new parameters or deleted, change
the original procedure back to its original parameters, fix the calling procedure,
then change the called procedure.
A procedure can be altered by its creator, the SYSDBA user, and any users with
operating system root privileges. Procedures in use are not altered until they are
no longer in use. ALTER PROCEDURE changes take effect when they are
committed. Changes are then reflected in all applications that use the procedure
without recompiling or relinking.
Example
The following isql statements alter the GET_EMP_PROJ procedure, changing the
return parameter to have a datatype of VARCHAR(20):
ALTER PROCEDURE GET_EMP_PROJ (EMP_NO SMALLINT)
RETURNS (PROJ_ID VARCHAR(20)) AS
BEGIN
FOR SELECT PROJ_ID
FROM EMPLOYEE_PROJECT
WHERE EMP_NO = :emp_no
INTO :proj_id
DO
SUSPEND;
END;
See also
2-17
For more information on creating and using procedures, see the Data Definition
Guide.
ALTER TABLE
Changes a table by adding, dropping, or modifying columns or integrity
constraints. Available in gpre, DSQL, and isql.
Important
Syntax
To alter a SQL global temporary table see: Altering a SQL global temporary table
in the Data Definition Guide.
ALTER TABLE table operation [, operation ];
operation = ADD col_def
| ADD tconstraint
| ALTER [COLUMN] column_name alt_col_clause
| DROP col
| DROP CONSTRAINT constraint
alt_col_clause = TO new_col_name
| TYPE new_col_datatype
| POSITION new_col_position
col_def = col {datatype | COMPUTED [BY] (expr) | domain}
[DEFAULT {literal | NULL | USER}]
[NOT NULL]
[col_constraint]
[COLLATE collation]
datatype =
{SMALLINT | INTEGER | FLOAT | DOUBLE PRECISION}[array_dim]
| (DATE | TIME | TIMESTAMP}[array_dim]
| {DECIMAL | NUMERIC} [(precision [, scale])] [array_dim]
| {CHAR | CHARACTER | CHARACTER VARYING | VARCHAR} [(int)]
[array_dim] [CHARACTER SET charname]
| {NCHAR | NATIONAL CHARACTER | NATIONAL CHAR}
[VARYING] [(int)] [array_dim]
| BLOB [SUB_TYPE {int | subtype_name}] [SEGMENT SIZE int]
[CHARACTER SET charname]
| BLOB [(seglen [, subtype])]array_dim = [[x:]y [, [x:]y
]]
| BOOLEAN
expr = A valid SQL expression that results in a single
value.
col_constraint = [CONSTRAINT constraint]
{ UNIQUE
| PRIMARY KEY
2-18
Language Reference
2-19
The column constraints for referential integrity were new in InterBase 5. See
constraint_def in Table 2.5 and the Description for ALTER TABLE on page
2-22.
You cannot specify a COLLATE clause for Blob columns.
When declaring arrays, you must include the outermost brackets, shown below
in bold. For example, the following statement creates a 5 by 5 two-dimensional
array of strings, each of which is 6 characters long:
my_array = varchar(6)[5,5]
Use the colon (:) to specify an array with a starting point other than 1. The
following example creates an array of integers that begins at 20 and ends at 30:
my_array = integer[20:30]
For the full syntax of search_condition, see CREATE TABLE.
Table 2.5 The ALTER TABLE statement
2-20
Argument
Description
table
operation
col_def
col
datatype
Language Reference
Description
ALTER [COLUMN]
domain
DEFAULT
CONSTRAINT constraint
constraint_def
CHECK search_condition
REFERENCES
2-21
Description
ON DELETE | ON UPDATE
NOT NULL
Description
DROP CONSTRAINT
table_constraint
COLLATE collation
ALTER TABLE modifies the structure of an existing table. A single ALTER TABLE
2-22
Language Reference
Important
The following isql statement adds a column to a table and drops a column:
ALTER TABLE COUNTRY
ADD CAPITAL VARCHAR(25),
DROP CURRENCY;
This statement results in the loss of all data in the dropped CURRENCY column.
The next isql statement changes the name of the LARGEST_CITY column to
BIGGEST_CITY:
For more information about altering tables, see the Embedded SQL Guide.
For detailed information on encryption and decryption, see the topics Encrypting
Data (page 13-9) and Decrypting Data (page 13-11) in the Data Definition
Guide.
2-23
ALTER TRIGGER
Changes an existing trigger. Available in DSQL and isql.
Syntax
Description
Description
name
ACTIVE
INACTIVE
BEFORE
AFTER
DELETE|INSERT
|UPDATE
POSITION number
Specifies order of firing for triggers before the same action or after
the same action
number must be an integer between 0 and 32,767, inclusive
Lower-number triggers fire first
Triggers for a table need not be consecutive; triggers on the
same action with the same position number fire in random order
trigger_body
Header information only, including the trigger activation status, when it performs
its actions, the event that fires the trigger, and the order in which the trigger fires
compared to other triggers.
Body information only, the trigger statements that follow the AS clause.
Header and trigger body information. In this case, the new trigger definition
replaces the old trigger definition.
2-24
Language Reference
A trigger can be altered by its creator, the SYSDBA user, and any users with
operating system root privileges.
Note
Examples
See also
ALTER USER
Change an existing user. Available in DSQL and isql.
Syntax
2-25
Description
Note
Examples
Argument
Description
PASSWORD
Password of user
Default role
[NO] UID
Target user ID
[NO] GID
[NO] DESCRIPTION
Description
ACTIVE
INACTIVE
Alter user changes the definition of an existing user. Only used with database
under embedded user authentication.
When NO is specified, an arguement to the option must not be supplied. No sets
the option to a NULL state.
The following statement modifies the user, JDOE, to be inactive:
ALTER USER JDOE SET INACTIVE;
The next statement modifies the user, JDOE, to be active:
ALTER USER JDOE SET ACTIVE;
See also
For more information about embedded user authentication, see the Operations
Guide.
AVG( )
Calculates the average of numeric values in a specified column or expression.
Available in gpre, DSQL, and isql.
Syntax
2-26
Language Reference
Description
Argument
Description
ALL
DISTINCT
value
AVG() is an aggregate function that returns the average of the values in a specified
column or expression. Only numeric datatypes are allowed as input to AVG().
Examples
The following embedded SQL statement returns the average of all rows in a table:
EXEC SQL
SELECT AVG (BUDGET) FROM DEPARTMENT INTO :avg_budget;
The next embedded SQL statement demonstrates the use of SUM(), AVG(), MIN(),
and MAX() over a subset of rows in a table:
EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX
(BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
See also
BASED ON
Declares a host-language variable based on a column. Available in gpre.
Syntax
2-27
Description
Argument
Description
dbhandle
table.col
.SEGMENT
Bases the local variable size on the segment length of the Blob column
during BLOB FETCH operations; use only when table.col refers to a
column of BLOB datatype
variable
on a column definition. The host variable inherits the attributes described for the
column and any characteristics that make the variable type consistent with the
programming language in use. For example, in C, BASED ON adds one byte to
CHAR and VARCHAR variables to accommodate the NULL character terminator.
Use BASED ON in a programs variable declaration section.
Note
size is derived from the segment length of a Blob column. If the segment length for
the Blob column is changed in the database, recompile the program to adjust the
size of host variables created with BASED ON.
Examples
See also
2-28
Language Reference
Description
BEGIN DECLARE SECTION must always appear within a modules global variable
declaration section.
Example
See also
CASE
The CASE function allows you to evaluate a column value on a row against
multiple criteria, where each criterion might return a different value.
Syntax
Description
CASE <expression>
WHEN <expression> THEN <expression> | NULL
[ELSE <expression> | NULL]
[COALESCE <expression>]
[NULLIF <expression, expression, ...>]
END
The CASE expression is a conditional value expression that consists of a list of value
expressions, each of which is associated with a conditional expression. A CASE expression
evaluates to the first value expression in the list for which its associated conditional expression
evaluates to TRUE. The CASE expression has simple and searched forms of syntax.
The COALESCE and NULLIF expressions are common, shorthand forms of use for the CASE
expression involving the NULL state. A COALESCE expression consists of a list of value
expressions. It evaluates to the first value expression in the list that evaluates to non-NULL. If
none of the value expressions in the list evaluates to non-NULL then the COALESCE expression
evaluates to NULL.
The NULLIF expression consists of a list of two value expressions. If the two expressions are
unequal then the NULLIF expression evaluates to the first value expression in the list. Otherwise,
it evaluates to NULL.
Example
The following example demonstrates the use of CASE using the sample
employee.ib database:
select emp.first_name || ' ' || emp.last_name as name,
case proj.proj_name
when 'DigiPizza' then 'Digital Pizza'
2-29
CAST( )
Converts a column from one datatype to another. Available in gpre, DSQL, and
isql.
Syntax
Description
Description
val
datatype
2-30
To datatype class
Numeric
Date
Time
Timestamp
Blob, arrays
Boolean
Language Reference
An error results if a given datatype cannot be converted into the datatype specified
in CAST(). For example, you will get a string conversion error if you attempt to cast
from a
numeric type which is unable to represent in a date type to a date (e.g. a numeric
type attempting to represent "year 99/12/31"(December) or "year 32768/3/
1"(March))
Example
See also
UPPER( )
CLOSE
Closes an open cursor. Available in gpre.
Syntax
Description
CLOSE cursor;
Argument
Description
cursor
CLOSE terminates the specified cursor, releasing the rows in its active set and any
associated system resources. A cursor is a one-way pointer into the ordered set of
rows retrieved by the select expression in the DECLARE CURSOR statement. A
cursor enables sequential access to retrieved rows in turn and update in place.
Statement
Purpose
DECLARE CURSOR
OPEN
FETCH
CLOSE
2-31
See also
CLOSE (BLOB)
Terminates a specified Blob cursor and releases associated system resources.
Available in gpre.
Syntax
Description
CLOSE blob_cursor;
Argument
Description
blob_cursor
CLOSE closes an opened read or insert Blob cursor. Generally a Blob cursor should
only be closed only after:
See also
DECLARE CURSOR (BLOB), FETCH (BLOB), INSERT CURSOR (BLOB), OPEN (BLOB)
COALESCE( )
The COALESCE function evaluates to the first value expression in a list that evaluates to
non-NULL. If none of the value expressions in the list evaluates to non-NULL then the
COALESCE expression evaluates to NULL.
Syntax
Description
2-32
COALESCE(<expression1>,<expression2>,...<expression_n>)
The COALESCE and NULLIF expressions are common, shorthand forms of use for the CASE
expression involving the NULL state. A COALESCE expression consists of a list of value
expressions. It evaluates to the first value expression in the list that evaluates to non-NULL. If
none of the value expressions in the list evaluates to non-NULL then the COALESCE expression
evaluates to NULL.
Language Reference
Example
The following example demonstrates the use of CASE using the sample
employee.ib database:
select coalesce(department, head_dept, location) from department
COMMIT
Makes a transactions changes to the database permanent, and ends the
transaction. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
WORK
TRANSACTION name
RELEASE
RETAIN [SNAPSHOT]
Important
The RELEASE argument is only available for compatibility with previous versions of
InterBase. To detach from a database use DISCONNECT.
Examples
The following isql statement makes permanent the changes to the database made
by the default transaction:
COMMIT;
The next embedded SQL statement commits a named transaction:
2-33
EXEC SQL
COMMIT TR1;
The following embedded SQL statement uses COMMIT RETAIN to commit changes
while maintaining the current transaction context:
EXEC SQL
COMMIT RETAIN;
See also
DISCONNECT, ROLLBACK
For more information about handling transactions, see the Embedded SQL Guide.
CONNECT
Attaches to one or more databases. Available in gpre. A subset of CONNECT
options is available in isql.
Syntax
isql form:
2-34
Argument
Description
{ALL | DEFAULT}
'filespec'
dbhandle
:variable
AS dbhandle
Language Reference
Argument
Description
USER {'username' |
:variable}
PASSWORD {password |
:variable}
Description
2-35
Attaches to the database and verifies the header page. The database file must
contain a valid database, and the on-disk structure (ODS) version number of the
database must be the one recognized by the installed version of InterBase on
the server, or InterBase returns an error.
Optionally establishes a database handle declared in a SET DATABASE
statement.
Specifies a cache buffer for the process attaching to a database.
In SQL programs before a database can be opened with CONNECT, it must be
declared with the SET DATABASE statement. isql does not use SET DATABASE.
In SQL programs while the same CONNECT statement can open more than one
database, use separate statements to keep code easy to read.
When CONNECT attaches to a database, it uses the default character set (NONE),
or one specified in a previous SET NAMES statement.
In SQL programs the CACHE option changes the database cache size count (the
total number of available buffers) from the default of 75. This option can be used
to:
Sets a new default size for all databases listed in the CONNECT statement that
do not already have a specific cache size.
Specifies a cache for a program that uses a single database.
Changes the cache for one database without changing the default for all
databases used by the program.
The size of the cache persists as long as the attachment is active. If a database is
already attached through a multi-client server, an increase in cache size due to a
new attachment persists until all the attachments end. A decrease in cache size
does not affect databases that are already attached through a server.
A subset of CONNECT features is available in isql: database file name, USER, and
PASSWORD. isql can only be connected to one database at a time. Each time
CONNECT is used to attach to a database, previous attachments are disconnected.
Examples
The following statement opens a database for use in isql. It uses all the CONNECT
options available to isql:
CONNECT 'employee.ib' USER 'ACCT_REC' PASSWORD 'peanuts';
The next statements, from an embedded application, attach to a database file
stored in the host-language variable and assign a previously declared database
handle to it:
EXEC SQL
SET DATABASE DB1 = 'employee.ib';
EXEC SQL
CONNECT :db_file AS DB1;
2-36
Language Reference
Se the Data Definition Guide for more information about cache buffers and the
Operations Guide for more information about database security and isql.
COUNT( )
Calculates the number of rows that satisfy a querys search condition. Available in
gpre, DSQL, and isql.
Syntax
2-37
Description
Argument
Description
ALL
DISTINCT
val
A column or expression
COUNT() is an aggregate function that returns the number of rows that satisfy a
querys search condition. It can be used in views and joins as well as in tables.
Example
The following embedded SQL statement returns the number of unique currency
values it encounters in the COUNTRY table:
EXEC SQL
SELECT COUNT (DISTINCT CURRENCY) INTO :cnt FROM COUNTRY;
See also
CREATE DATABASE
Creates a new database. Available in gpre, DSQL, and isql.
Syntax
Important
2-38
Language Reference
Argument
Description
filespec
USER username
PASSWORD
password
WITH ADMIN
OPTION
DEFAULT
CHARACTER SET
charset
FILE filespec
int
Specifies the length of a primary or secondary database file
Use for primary file only if defining a secondary file in the
same statement
LENGTH [=]
int [PAGE[S]]
Description
CREATE DATABASE creates a new, empty database and establishes the following
2-39
Increasing page size can improve performance for the following reasons:
Indexes work faster because the depth of the index is kept to a minimum.
Keeping large rows on a single page is more efficient.
Blob data is stored and retrieved more efficiently when it fits on a single page.
If most transactions involve only a few rows of data, a smaller page size might
be appropriate, since less data needs to be passed back and forth and less
memory is used by the disk cache.
The number of pages in each database file.
The dialect of the database.
The initial dialect of the database is the dialect of the client that creates it. For
example, if you are using isql, either start it with the -sql_dialect n switch or issue
the SET SQL DIALECT n command before issuing the CREATE DATABASE
command. Typically, you would create all databases in dialect 3. Dialect 1 exists
to ease the migration of legacy databases.
To change the dialect of a database, use gfix or the Properties dialog in
IBConsole. See the Migration appendix in the InterBase Operations Guide for
information about migrating databases.
The character set used by the database.
For a list of the character sets recognized by InterBase, see Chapter 7,
Character Sets and Collation Orders.
2-40
In DSQL, you must execute CREATE DATABASE EXECUTE IMMEDIATE. The database
handle and transaction name, if present, must be initialized to zero prior to use.
Language Reference
Read-only databases
Databases are always created in read-write mode. You can change a table to readonly mode in one of two ways: you can specify mode -read_only when you restore
a backup, or you can use gfix -mode read_only to change the mode of a table to
read-only. See Chapter 6 in the Operations Guide for more information on
database configuration and maintenance.
About file sizes
The following isql statement creates a database in the current directory using isql:
CREATE DATABASE 'employee.ib';
The next embedded SQL statement creates a database with a page size of 2048
bytes rather than the default of 4096:
EXEC SQL
CREATE DATABASE 'employee.ib' PAGE_SIZE 2048;
The following embedded SQL statement creates a database stored in two files and
specifies its default character set:
EXEC SQL
CREATE DATABASE 'employee.ib'
DEFAULT CHARACTER SET ISO8859_1
FILE 'employee2.ib' STARTING AT PAGE 10001;
See also
See the Data Definition Guide for more information about secondary files,
character set specification, and collation order; see the Operations Guide for more
information about page size.
CREATE DOMAIN
Creates a column definition that is global to the database. Available in gpre, DSQL,
and isql.
Syntax
2-41
datatype> =
{SMALLINT|INTEGER|FLOAT|DOUBLE PRECISION}[array_dim]
| {DATE|TIME|TIMESTAMP}[array_dim]
| {DECIMAL | NUMERIC} [(precision [, scale])] [array_dim]
| {CHAR | CHARACTER | CHARACTER VARYING | VARCHAR} [(int)]
[array_dim] [CHARACTER SET charname]
| {NCHAR | NATIONAL CHARACTER | NATIONAL CHAR}
[VARYING] [(int)] [array_dim]
| BLOB [SUB_TYPE {int | subtype_name}] [SEGMENT SIZE int]
[CHARACTER SET charname]
| BLOB [(seglen [, subtype])]
| BOOLEAN
array_dim> = [[x:]y [, [x:]y ]]
dom_search_condition> =
VALUE operator value
| VALUE [NOT] BETWEEN value AND value
| VALUE [NOT] LIKE value [ESCAPE value]
| VALUE [NOT] IN (value [, value ])
| VALUE IS [NOT] NULL
| VALUE [NOT] CONTAINING value
| VALUE [NOT] STARTING [WITH] value
| (dom_search_condition)
| NOT dom_search_condition
| dom_search_condition OR dom_search_condition
| dom_search_condition AND dom_search_condition
operator> = {= | < | > | <= | >= | !< | !> | <> | !=}
Note on the CREATE DOMAIN syntax
COLLATE is useful only for text data, not for numeric types. Also, you cannot
specify a COLLATE clause for Blob columns.
When declaring arrays, you must include the outermost brackets, shown below
in bold. For example, the following statement creates a 5 by 5 two-dimensional
array of strings, each of which is six characters long:
my_array = varchar(6)[5,5]
Use the colon (:) to specify an array with a starting point other than 1. The
following example creates an array of integers that begins at 20 and ends at 30:
my_array = integer[20:30]
Important
2-42
Language Reference
Description
Argument
Description
domain
datatype
SQL datatype
DEFAULT
NOT NULL
CHECK (dom_search_condition)
VALUE
COLLATE collation
CREATE DOMAIN builds an inheritable column definition that acts as a template for
columns defined with CREATE TABLE or ALTER TABLE. The domain definition
contains a set of characteristics, which include:
Datatype
An optional default value
Optional disallowing of NULL values
An optional CHECK constraint
An optional collation clause
The CHECK constraint in a domain definition sets a dom_search_condition that
must be true for data entered into columns based on the domain. The CHECK
constraint cannot reference any domain or column.
Note
2-43
If you do not specify a default character set, the character set defaults to NONE.
Using character set NONE means that there is no character set assumption for
columns; data is stored and retrieved just as you originally entered it. You can load
any character set into a column defined with NONE, but you cannot load that same
data into another column that has been defined with a different character set. In
these cases, no transliteration is performed between the source and destination
character sets, so errors can occur during assignment.
The COLLATE clause enables specification of a particular collation order for CHAR,
VARCHAR, and NCHAR text datatypes. Choice of collation order is restricted to
those supported for the domains given character set, which is either the default
character set for the entire database, or a different set defined in the CHARACTER
SET clause as part of the datatype definition. For a complete list of collation orders
recognized by InterBase, see Chapter 7, Character Sets and Collation Orders.
Columns based on a domain definition inherit all characteristics of the domain. The
domain default, collation clause, and NOT NULL setting can be overridden when
defining a column based on a domain. A column based on a domain can add
additional CHECK constraints to the domain CHECK constraint.
Examples
The following isql statement creates a domain that must have a positive value
greater than 1,000, with a default value of 9,999. The keyword VALUE substitutes
for the name of a column based on this domain.
CREATE DOMAIN CUSTNO
AS INTEGER
DEFAULT 9999
CHECK (VALUE > 1000);
The next isql statement limits the values entered in the domain to four specific
values:
CREATE DOMAIN PRODTYPE
AS VARCHAR(12)
CHECK (VALUE IN ('software', 'hardware', 'other', 'N/A'));
The following isql statement creates a domain that defines an array of CHAR
datatype:
CREATE DOMAIN DEPTARRAY AS CHAR(67) [4:5];
In the following isql example, the first statement creates a domain with USER as the
default. The next statement creates a table that includes a column, ENTERED_BY,
based on the USERNAME domain.
CREATE DOMAIN USERNAME AS VARCHAR(20)
DEFAULT USER;
CREATE TABLE ORDERS (ORDER_DATE DATE, ENTERED_BY USERNAME,
ORDER_AMT DECIMAL(8,2));
INSERT INTO ORDERS (ORDER_DATE, ORDER_AMT)
VALUES ('1-MAY-93', 512.36);
2-44
Language Reference
The INSERT statement does not include a value for the ENTERED_BY column, so
InterBase automatically inserts the user name of the current user, JSMITH:
SELECT * FROM ORDERS;
1-MAY-93 JSMITH 512.36
The next isql statement creates a BLOB domain with a TEXT subtype that has an
assigned character set:
CREATE DOMAIN DESCRIPT AS
BLOB SUB_TYPE TEXT SEGMENT SIZE 80
CHARACTER SET SJIS;
See also
For more information about character set specification and collation orders, see
the Data Definition Guide.
CREATE ENCRYPTION
Creates encryption keys for use during the encryption process.
Syntax
Description
Argument
Description
Key-name
For AES|DES
The following isql statement creates an encryption key called revenue_key using
the AES encryption scheme and a length of 192 bits:
See also
2-45
For detailed information on encryption and decryption, see the topics Encrypting
Data (page 13-9) and Decrypting Data (page 13-11) in the Data Definition
Guide.
CREATE EXCEPTION
Creates a used-defined error and associated message for use in stored
procedures and triggers. Available in DSQL and isql.
Syntax
Important
Description
Description
name
message
Exceptions are global to the database. The same message or set of messages is
available to all stored procedures and triggers in an application. For example, a
database can have English and French versions of the same exception messages
and use the appropriate set as needed.
When raised by a trigger or a stored procedure, an exception:
Terminates the trigger or procedure in which it was raised and undoes any
actions performed (directly or indirectly) by it.
Returns an error message to the calling application. In isql, the error message
appears on the screen, unless output is redirected.
Exceptions may be trapped and handled with a WHEN statement in a stored
procedure or trigger.
Examples
2-46
Language Reference
For more information on creating, raising, and handling exceptions, see the Data
Definition Guide.
CREATE GENERATOR
Declares a generator to the database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
CREATE GENERATOR declares a generator to the database and sets its starting
value to zero. A generator is a sequential number that can be automatically
inserted in a column with the GEN_ID() function. A generator is often used to ensure
a unique value in a PRIMARY KEY, such as an invoice number, that must uniquely
identify the associated row.
A database can contain any number of generators. Generators are global to the
database, and can be used and updated in any transaction. InterBase does not
assign duplicate generator values across transactions.
You can use SET GENERATOR to set or change the value of an existing generator
when writing triggers, procedures, or SQL statements that call GEN_ID().
See also
CREATE INDEX
Creates an index on one or more columns in a table. Available in gpre, DSQL, and
isql.
Syntax
2-47
Important
Description
Important
Description
UNIQUE
ASC[ENDING]
DESC[ENDING]
index
table
col
Creates an index on one or more columns in a table. Use CREATE INDEX to improve
speed of data access. Using an index for columns that appear in a WHERE clause
may improve search performance.
You cannot index Blob columns or arrays.
A UNIQUE index cannot be created on a column or set of columns that already
contains duplicate or NULL values.
ASC and DESC specify the order in which an index is sorted. For faster response to
queries that require sorted values, use the index order that matches the querys
ORDER BY clause. Both an ASC and a DESC index can be created on the same
column or set of columns to access data in different orders.
Tip
Examples
See also
2-48
Language Reference
CREATE JOURNAL
Creates a journal file and activates journaling.
Syntax
Argument
Description
journal-filespecification
LENGTH
CHECKPOINT
LENGTH
CHECKPOINT
INTERVAL
PAGE SIZE
2-49
Argument
Description
PAGE CACHE
[NO] TIMESTAMP
NAME
[NO] PREALLOCATE
Description
A journal consists of one or more journal files. A journal file records each database
transaction as it occurs. To save changed journal pages in the database cache to
the hard disk, you set up journaling checkpoints to occur automatically. A
checkpoint specifies the time at which InterBase must save all the changed pages
in the database cache to the database file.
The CREATE JOURNAL statement causes all subsequent write operations on a
database to be done asynchronously. The journal file I/O is always synchronous
and cannot be altered. All transaction changes are safely recorded on durable
storage before the transaction is committed.
Journaling can be used with journal archiving to provide more complete disaster
recovery.
Example
The LENGTH parameter of 65000 will cause rollover to a new journal file every 1GB
(65000 x 16KB). A CHECKPOINT LENGTH parameter of 10000 means the database
checkpoint will occur every 160MB (10000 x 16KB). The 2500 journal buffer
configuration will leave 2000 spare buffers for the worker threads to dump their
journal changes. At the built-in PAGE CACHE default of 100, the worker threads can
stall due to a high rate of journal buffer wait states.
See also
For more information about journals, journal files, and journal archives, see the
Operations Guide.
2-50
Language Reference
Description
Important
See also
Argument
Description
journal archive
directory
The CREATE JOURNAL ARCHIVE command performs two functions: it activates journal
archiving in an InterBase database, and it automatically performs the initial full,
physical dump of the database. InterBase stores the dump in the journal archive
directory you specify in the CREATE statement. A journal archive enables you to
recover to the last committed transaction in the most recently archived and
completed journal file.
creates the archive and performs an initial dump.
However, you must issue a specific gbak command to copy completed journal files
to the journal archive. You use another gbak command to perform subsquent
dumps to the archive. For information about the gbak archive commands, and
about how to implement journaling and journal archiving, see the InterBase
Operations Guide..
CREATE JOURNAL ARCHIVE
Archived database dumps represent the starting point from which long-term
database recovery is initiated. A set of archive journal files are applied to a copy of
the archive database in the same way that local journal files are applied to a
production database during short-term recovery. Also, an InterBase timestamp can
be specified to indicate a point-in-time until which the journal files will be applied.
2-51
When the archive is used to recover a database, the resulting database is not a
journaled database. This means that RDB$LOG_FILES, RDB$JOURNAL_FILES
and the log page of the database are empty. This prevents the database from
accidently using the journal and journal archive of an existing database. Database
recovery is usually used when the original database is corrupted or unavailable
due to hardware failures. However, it could be possible to recover a database on
the same machine as the working production database or on a different machine
where the journal and journal archive directories have no similarly-named
directories. Therefore, if journaling and/or journal archiving is desired for the
recovered database, it is necessary to execute the appropriate DDL commands to
do so.
Examples
Gbak is used to archive databases and journal files to the archive, and is also used
to recover a database from the archive back to a specified local directory of the
user's choice.
To archive a database:
gbak -archive_database <dbname>
To archive local journal files:
gbak -archive_journals <dbname>
To recover a database (optionally to a point-in-time)
gbak -archive_recover [-until <timestamp>] <archive_dbname> <local_dbname>
If the -until command line switch is not given, the database recover applies as
many jounral files as possible to recover a database to the most recent point-intime. If possible, the database recovery attempts to "jump" from the archive to the
local journal directory to apply the journal files that were never copied to the
archive. In this way, a database may be recovered to the most recently committed
transaction of the original database.
If allowed, the archive grows in storage size infinitely as the database and the most
curnrent journal files are continually archived. Gfix is used to manage and garbage
collect archived items that are no longer required As the number of journal files
grows in the archive without have created more recent archived database dumps,
so does the time that will be needed to recover the database from the archive.
Therefore, it is desirable to periodically create additional database dumps in the
archive. At some point, you may decided that older database dumps and the
journal files on which they depend on are no longer necessary, as the basis of
recovery will be on more recent database dumps and journal files.
All archive items are denoted by an archive sequence number that corresponds to
the order
in which the items were created in the archive.
2-52
Language Reference
Listed below are the requirements and constraints for managing the Journal
Archive.
2-53
CREATE PROCEDURE
Creates a stored procedure, its input and output parameters, and its actions.
Available in DSQL, and isql.
Syntax
2-54
Language Reference
Argument
Description
name
param datatype
AS
DECLARE VARIABLE
var datatype
statement
Description
2-55
2-56
Language Reference
Description
BEGIN END
variable = expression
/* comment_text */
EXCEPTION exception_name
Raises the named exception: an exception is a userdefined error that returns an error message to the calling
application unless handled by a WHEN statement
EXECUTE PROCEDURE
EXIT
FOR select_statement
DO compound_statement
compound_statement
IF (condition)
THEN compound_statement
[ELSE compound_statement]
NEW.column
OLD.column
2-57
Description
SUSPEND
In a SELECT procedure:
Suspends execution of procedure until next FETCH is
issued by the calling application
Returns output values, if any, to the calling application
Not recommended for executable procedures
WHILE (condition)
DO compound_statement
DO compound_statement
The stored procedure and trigger language does not include many of the
statement types available in DSQL or gpre. The following statement types are not
supported in triggers or stored procedures:
Data definition language statements: CREATE, ALTER, DROP, DECLARE
EXTERNAL FUNCTION, and DECLARE FILTER
Transaction control statements: SET TRANSACTION, COMMIT, ROLLBACK
Dynamic SQL statements: PREPARE, DESCRIBE, EXECUTE
CONNECT/DISCONNECT, and sending SQL statements to another database
GRANT/REVOKE
SET GENERATOR
EVENT INIT/WAIT
BEGIN/END DECLARE SECTION
BASED ON
WHENEVER
DECLARE CURSOR
OPEN
FETCH
2-58
Language Reference
Examples
2-59
FROM EMPLOYEE
WHERE DEPT_NO = :dno
INTO :emp_cnt;
SUSPEND;
END
END ;
When ORG_CHART is invoked, for example in the following isql statement:
SELECT * FROM ORG_CHART
it displays the department name for each department, which department it is in, the
department managers name and title, and the number of employees in the
department.
HEAD_DEPT
DEPARTMENT
MGR_NAME
TITLE
================
====
=======
Corporate Headquarters
Bender, Oliver H.
CEO
Corporate Headquarters
MacDonald, Mary S.
VP
Baldwin, Janet ?
Sales
Yamamoto, Takashi
SRep
TBH
===================== ===================
EMP_CNT
See also
For more information on creating and using procedures, see the Data Definition
Guide.
CREATE ROLE
Creates a role.
Syntax
Important
2-60
Language Reference
Description
Example
Argument
Description
rolename
Roles created with CREATE ROLE can be granted privileges just as users can.
These roles can be granted to users, who then inherit the privilege list that has
been granted to the role. Users must specify the role at connect time. Use GRANT
to grant privileges (ALL, SELECT, INSERT, UPDATE, DELETE, EXECUTE, REFERENCES)
to a role and to grant a role to users. Use REVOKE to revoke them.
The following statement creates a role called administrator.
CREATE ROLE administrator;
See also
CREATE SHADOW
Creates one or more duplicate, in-sync copies of a database. Available in gpre,
DSQL, and isql.
Syntax
Important
Description
set_num
AUTO
MANUAL
2-61
Description
Argument
Description
CONDITIONAL
filespec
Explicit path name and file name for the shadow file; must
be a local file system and must not include a node name
or be on a networked file system
secondary_file
To add a secondary file to an existing disk shadow, drop the shadow with DROP
SHADOW and use CREATE SHADOW to recreate it with the desired number of files.
The following isql statement creates a single, automatic shadow file for
employee.ib:
CREATE SHADOW 1 AUTO 'employee.shd';
2-62
Language Reference
The next isql statement creates a conditional, single, automatic shadow file for
employee.ib:
CREATE SHADOW 2 CONDITIONAL 'employee.shd' LENGTH 1000;
The following isql statements create a multiple-file shadow set for the employee.ib
database. The first statement specifies starting pages for the shadow files; the
second statement specifies the number of pages for the shadow files.
CREATE SHADOW 3 AUTO
'employee.sh1'
FILE 'employee.sh2'
STARTING AT PAGE 1000
FILE 'employee.sh3'
STARTING AT PAGE 2000;
CREATE SHADOW 4 MANUAL 'employee.sdw'
LENGTH 1000
FILE 'employee.sh1'
LENGTH 1000
FILE 'employee.sh2';
See also
DROP SHADOW
For more information about using shadows, see the Operations Guide or the Data
Definition Guide.
CREATE TABLE
Creates a new table in an existing database. Available in gpre, DSQL, and isql.
Important
Syntax
To create a SQL Global Temporary table see: SQL global temporary tables in the
Data Definition Guide
CREATE TABLE table [EXTERNAL [FILE] 'filespec']
(col_def [, col_def | tconstraint ]);
col_def = col {datatype | COMPUTED [BY] (expr) | domain}
[DEFAULT {literal | NULL | USER}]
[NOT NULL]
[col_constraint]
[COLLATE collation]
datatype =
{SMALLINT | INTEGER | FLOAT | DOUBLE PRECISION}[array_dim]
| (DATE | TIME | TIMESTAMP}[array_dim]
| {DECIMAL | NUMERIC} [(precision [, scale])] [array_dim]
| {CHAR | CHARACTER | CHARACTER VARYING | VARCHAR} [(int)]
[array_dim] [CHARACTER SET charname]
| {NCHAR | NATIONAL CHARACTER | NATIONAL CHAR}
[VARYING] [(int)] [array_dim]
| BLOB [SUB_TYPE {int | subtype_name}] [SEGMENT SIZE int]
[CHARACTER SET charname]
2-63
2-64
Language Reference
Important
When declaring arrays, you must include the outermost brackets, shown below
in bold. For example, the following statement creates a 5 by 5 two-dimensional
array of strings, each of which is 6 characters long:
my_array VARCHAR(6)[5,5]
Use the colon (:) to specify an array with a starting point other than 1. The
following example creates an array of integers that begins at 10 and ends at 20:
my_array INTEGER[10:20]
In SQL and isql, you cannot use val as a parameter placeholder (like ?).
In DSQL and isql, val cannot be a variable.
You cannot specify a COLLATE clause for Blob columns.
expr is any complex SQL statement or equation that produces a single value.
2-65
2-66
Argument
Description
table
col
datatype
domain
DEFAULT
CONSTRAINT constraint
constraint_def
REFERENCES
Language Reference
Description
Argument
Description
ON DELETE | ON UPDATE
CHECK search_condition
COLLATE collation
CREATE TABLE establishes a new table, its columns, and integrity constraints in an
existing database. The user who creates a table is the tables owner and has all
privileges for it, including the ability to GRANT privileges to other users, triggers,
and stored procedures.
CREATE TABLE supports several options for defining columns:
Local columns specify the name and datatype for data entered into the
column.
Computed columns are based on an expression. Column values are
computed each time the table is accessed. If the datatype is not specified,
InterBase calculates an appropriate one. Columns referenced in the
expression must exist before the column can be defined.
Domain-based columns inherit all the characteristics of a domain, but the
column definition can include a new default value, a NOT NULL attribute,
additional CHECK constraints, or a collation clause that overrides the domain
definition. It can also include additional column constraints.
The datatype specification for a CHAR, VARCHAR, or Blob text column
definition can include a CHARACTER SET clause to specify a particular
character set for the single column. Otherwise, the column uses the default
database character set. If the database character set is changed, all columns
subsequently defined have the new character set, but existing columns are
2-67
You can define integrity constraints at the time you create a table. These
constraints are rules that validate data entries by enforcing column-to-table and
table-to-table relationships. They span all transactions that access the database
and are automatically maintained by the system. CREATE TABLE supports the
following integrity constraints:
A PRIMARY KEY is one or more columns whose collective contents are
guaranteed to be unique. A PRIMARY KEY column must also define the NOT NULL
attribute. A table can have only one primary key.
2-68
Language Reference
UNIQUE keys ensure that no two rows have the same value for a specified
column or ordered set of columns. A unique column must also define the NOT
NULL attribute. A table can have one or more UNIQUE keys. A UNIQUE key can
be referenced by a FOREIGN KEY in another table.
Referential constraints (REFERENCES) ensure that values in the specified
columns (known as the foreign key) are the same as values in the referenced
UNIQUE or PRIMARY KEY columns in another table. The UNIQUE or PRIMARY KEY
columns in the referenced table must be defined before the REFERENCES
constraint is added to the secondary table. REFERENCES has ON DELETE and ON
UPDATE clauses that define the action on the foreign key when the referenced
primary key is updated or deleted. The values for ON UPDATE and ON DELETE
are as follows:
Action
specified
NO ACTION
[Default] The foreign key does not change. This may cause the
primary key update or delete to fail due to referential integrity
checks.
CASCADE
SET DEFAULT
SET NULL
You can create a FOREIGN KEY reference to a table that is owned by someone
else only if that owner has explicitly granted you REFERENCES privilege on that
table. Any user who updates your foreign key table must have REFERENCES or
SELECT privileges on the referenced primary key table.
CHECK constraints enforce a search_condition that must be true for inserts or
updates to the specified table. search_condition can require a combination or
range of values or can compare the value entered with data in other columns.
Note
Specifying USER as the value for a search_condition references the login of the user
who is attempting to write to the referenced table.
Creating PRIMARY KEY and FOREIGN KEY constraints requires exclusive access
to the database.
For unnamed constraints, the system assigns a unique constraint name stored
in the RDB$RELATION_CONSTRAINTS system table.
Chapter 2 SQL Statement and Function Reference
2-69
Note
Examples
2-70
Language Reference
DEFAULT 0
NOT NULL
CHECK (PERCENT_CHANGE BETWEEN -50 AND 50),
NEW_SALARY COMPUTED BY
(OLD_SALARY + OLD_SALARY * PERCENT_CHANGE / 100),
PRIMARY KEY (EMP_NO, CHANGE_DATE, UPDATER_ID),
FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE (EMP_NO));
In the following isql statement the first column retains the default collating order for
the databases default character set. The second column has a different collating
order, and the third column definition includes a character set and a collating order.
CREATE TABLE BOOKADVANCE (
BOOKNO CHAR(6),
TITLE CHAR(50) COLLATE ISO8859_1,
EUROPUB CHAR(50) CHARACTER SET ISO8859_1 COLLATE FR_FR);
See also
CREATE TRIGGER
Creates a trigger, including when it fires, and what actions it performs. Available in
DSQL, and isql.
Syntax
2-71
datatype = SMALLINT
| INTEGER
| FLOAT
| DOUBLE PRECISION
| {DECIMAL | NUMERIC} [(precision [, scale])]
| {DATE | TIME | TIMESTAMP)
| {CHAR | CHARACTER | CHARACTER VARYING | VARCHAR}
[(int)] [CHARACTER SET charname]
| {NCHAR | NATIONAL CHARACTER | NATIONAL CHAR} [VARYING]
[(int)]
| BOOLEAN
compound_statement = block | statement;
Argument
Description
name
table
Name of the table or view that causes the trigger to fire when
the specified operation occurs on the table or view
ACTIVE|INACTIVE
BEFORE|AFTER
DELETE|INSERT
|UPDATE
POSITION number
Specifies firing order for triggers before the same action or after
the same action; number must be an integer between 0 and
32,767, inclusive.
Lower-number triggers fire first
Default: 0 = first trigger to fire
Triggers for a table need not be consecutive; triggers on the
same action with the same position number will fire in random
order.
DECLARE VARIABLE
var datatype
statement
2-72
Language Reference
Description
2-73
The following table summarizes language extensions for triggers. For a complete
description of each statement, see Chapter 3, Procedures and Triggers.
Table 2.8 Language extensions for triggers
Statement
Description
BEGIN END
variable = expression
/* comment_text */
EXCEPTION exception_name
EXECUTE PROCEDURE
EXIT
FOR select_statement
DO compound_statement
select_statement
compound_statement
IF (condition)
THEN compound_statement
[ELSE compound_statement]
condition
NEW.column
2-74
Language Reference
Description
OLD.column
WHILE (condition)
DO compound_statement
error
The stored procedure and trigger language does not include many of the
statement types available in DSQL or gpre. The following statement types are not
supported in triggers or stored procedures:
Data definition language statements: CREATE, ALTER, DROP, DECLARE EXTERNAL
FUNCTION, and DECLARE FILTER
Transaction control statements: SET TRANSACTION, COMMIT, ROLLBACK
Dynamic SQL statements: PREPARE, DESCRIBE, EXECUTE
CONNECT/DISCONNECT, and sending SQL statements to another database
GRANT/REVOKE
SET GENERATOR
EVENT INIT/WAIT
BASED ON
WHENEVER
DECLARE CURSOR
OPEN
FETCH
2-75
Examples
2-76
Language Reference
1 Trigger B fires.
2 Trigger A fires.
3 The update occurs.
4 Trigger D fires.
5 Trigger C fires.
See also
For more information on creating and using triggers, see the Data Definition
Guide.
CREATE USER
Create a new user. Available in DSQL and isql.
Syntax
Description
PASSWORD
Password of user
Default role
2-77
Description
Note
Examples
Argument
Description
[NO] UID
Target user ID
[NO] GID
[NO] DESCRIPTION
Description
ACTIVE
INACTIVE
CREATE USER creates a new user. Only used with database under embedded
user authentication.
When NO is specified, an arguement to the option must not be supplied. No sets
the option to a NULL state.
The following statement creates the user, JDOE and set password, jdoe:
CREATE USER JDOE SET PASSWORD jdoe;
The next statement creates the user, JDOE, and set password, first name and last
name:
CREATE USER JDOE SET PASSWORD jdoe, FIRST NAME Jane, LAST NAME
Doe;
See also
For more information about embedded user authentication, see the Operations
Guide.
CREATE VIEW
Creates a new view of data from one or more tables. Available in gpre, DSQL, and
isql.
Syntax
Important
2-78
Language Reference
Description
Argument
Description
name
Name for the view; must be unique among all view, table, and
procedure names in the database
view_col
select
WITH CHECK
OPTION
CREATE VIEW describes a view of data based on one or more underlying tables in
the database. The rows to return are defined by a SELECT statement that lists
columns from the source tables. Only the view definition is stored in the database;
a view does not directly represent physically stored data. It is possible to perform
select, project, join, and union operations on views as if they were tables.
The user who creates a view is its owner and has all privileges for it, including the
ability to GRANT privileges to other users, roles, triggers, views, and stored
procedures. A user may have privileges to a view without having access to its base
tables. When creating views:
A read-only view requires SELECT privileges for any underlying tables.
An updatable view requires ALL privileges to the underlying tables.
The view_col option ensures that the view always contains the same columns and
that the columns always have the same view-defined names.
View column names correspond in order and number to the columns listed in the
SELECT clause, so specify all view column names or none.
A view_col definition can contain one or more columns based on an expression
that combines the outcome of two columns. The expression must return a single
value, and cannot return an array or array element. If the view includes an
expression, the view-column option is required.
Note
Any columns used in the value expression must exist before the expression can be
defined.
A SELECT statement clause cannot include the ORDER BY clause.
When SELECT * is used rather than a column list, order of display is based on the
order in which columns are stored in the base table.
2-79
Note
You cannot select from a view that is based on the result set of a stored procedure.
Note
An updatable view cannot have UNION clauses. To create such a view, use
embedded SQL.
A view is updatable if:
It is a subset of a single table or another updatable view.
All base table columns excluded from the view definition allow NULL values.
The views SELECT statement does not contain subqueries, a DISTINCT
predicate, a HAVING clause, aggregate functions, joined tables, user-defined
functions, or stored procedures.
If the view definition does not meet these conditions, it is considered read-only.
Note
Examples
2-80
Language Reference
DECLARE CURSOR
Defines a cursor for a table by associating a name with the set of rows specified in
a SELECT statement. Available in gpre and DSQL.
Syntax
SQL form:
Argument
Description
cursor
select
[, col ]
statement_id
Description
DECLARE CURSOR defines the set of rows that can be retrieved using the cursor it
names. It is the first member of a group of table cursor statements that must be
used in sequence.
2-81
select specifies a SELECT statement that determines which rows to retrieve. The
SELECT statement cannot include INTO or ORDER BY clauses.
The FOR UPDATE OF clause is necessary for updating or deleting rows using the
WHERE CURRENT OF clause with UPDATE and DELETE.
A cursor is a one-way pointer into the ordered set of rows retrieved by the select
expression in the DECLARE CURSOR statement. It enables sequential access to
retrieved rows in turn. There are four related cursor statements:
Stag
e
Examples
Statement
Purpose
DECLARE
CURSOR
OPEN
FETCH
Retrieves the current row from the active set, starting with the
first row; subsequent FETCH statements advance the cursor
through the set
CLOSE
The following embedded SQL statement declares a cursor with a search condition:
EXEC SQL
DECLARE C CURSOR FOR
SELECT CUST_NO, ORDER_STATUS
FROM SALES
WHERE ORDER_STATUS IN ('open', 'shipping');
The next DSQL statement declares a cursor for a previously prepared statement,
QUERY1:
DECLARE Q CURSOR FOR QUERY1
See also
2-82
Language Reference
Argument
Description
cursor
column
table
Table name
READ BLOB
INSERT BLOB
MAXIMUM_SEGMENT
length
Description
Declares a cursor for reading or inserting Blob data. A Blob cursor can be
associated with only one Blob column.
To read partial Blob segments when a host-language variable is smaller than the
segment length of a Blob, declare the Blob cursor with the MAXIMUM_SEGMENT
clause. If length is less than the Blob segment, FETCH returns length bytes. If the
same or greater, it returns a full segment (the default).
Examples
The following embedded SQL statement declares a READ BLOB cursor and uses
the MAXIMUM_SEGMENT option:
EXEC SQL
DECLARE BC CURSOR FOR
READ BLOB JOB_REQUIREMENT FROM JOB MAXIMUM_SEGMENT 40;
The next embedded SQL statement declares an INSERT BLOB cursor:
EXEC SQL
DECLARE BC CURSOR FOR
INSERT BLOB JOB_REQUIREMENt INTO JOB;
See also
2-83
Important
Note
Description
2-84
Description
name
Name of the UDF to use in SQL statements; can be different from the
name of the function specified after the ENTRY_POINT keyword
datatype
CSTRING (int)
RETURNS
BY VALUE
PARAMETER n
FREE_IT
Frees memory of the return value after the UDF finishes running
Use only if the memory is allocated dynamically in the UDF
See also Language Reference, Chapter 5
'entryname'
'modulename'
Language Reference
entryname is the actual name of the function as stored in the UDF library. It does
not have to match the name of the UDF as stored in the database.
Important
The module name does not need to include a path. However, the module must
either be placed in <InterBase_home>/UDF or be listed in the InterBase
configuration file using the EXTERNAL_FUNCTION_DIRECTORY parameter.
To specify a location for UDF libraries in the InterBase configuration file, enter a
line of the following form for Windows platforms:
EXTERNAL_FUNCTION_DIRECTORY D:\Mylibraries\InterBase
For UNIX, the line does not include a drive letter:
EXTERNAL_FUNCTION_DIRECTORY \Mylibraries\InterBase
The InterBase configuration file is called ibconfig on all platforms.
Examples
See also
For more information about writing UDFs and for a complete list of UDFs supplied
by InterBase, see Working with UDFs and Blob Filters in the Developers Guide.
DECLARE FILTER
Declares an existing Blob filter to a database. Available in gpre, DSQL, and isql.
Syntax
Important
2-85
Description
Argument
Description
filter
INPUT_TYPE subtype
OUTPUT_TYPE subtype
entryname
modulename
DECLARE FILTER provides information about an existing Blob filter to the database:
where to find it, its name, and the Blob subtypes it works with. A Blob filter is a
user-written program that converts data stored in Blob columns from one subtype
to another.
INPUT_TYPE and OUTPUT_TYPE together determine the behavior of the Blob filter.
Each filter declared to the database should have a unique combination of
INPUT_TYPE and OUTPUT_TYPE integer values. InterBase provides a built-in type of
1, for handling text. User-defined types must be expressed as negative values.
entryname is the name of the Blob filter stored in the library. When an application
uses a Blob filter, it calls the filter function with this name.
Example
See also
DROP FILTER
For instructions on writing Blob filters, see the Embedded SQL Guide.
For more information about Blob subtypes, see the Data Definition Guide.
DECLARE STATEMENT
Identifies dynamic SQL statements before they are prepared and executed in an
embedded program. Available in gpre.
Syntax
2-86
Language Reference
Description
Argument
Description
statement
The following embedded SQL statement declares Q1 to be the name of a string for
preparation and execution.
EXEC SQL
DECLARE Q1 STATEMENT;
See also
DECLARE TABLE
Describes the structure of a table to the preprocessor, gpre, before it is created
with CREATE TABLE. Available in gpre.
Syntax
Description
table
Name of the table; table names must be unique within the database
table_def
Definition of the table; for complete table definition syntax, see CREATE
TABLE
Description
DECLARE TABLE causes gpre to store a table description. You must use it if you
both create and populate a table with data in the same program. If the declared
table already exists in the database or if the declaration contains syntax errors,
gpre returns an error.
When a table is referenced at run time, the column descriptions and datatypes are
checked against the description stored in the database. If the table description is
not in the database and the table is not declared, or if column descriptions and
datatypes do not match, the application returns an error.
DECLARE TABLE can include an existing domain in a column definition, but must
give the complete column description if the domain is not defined at compile time.
DECLARE TABLE cannot include integrity constraints and column attributes, even if
they are present in a subsequent CREATE TABLE statement.
Important
Example
2-87
EXEC SQL
DECLARE STOCK TABLE
(MODEL SMALLINT,
MODELNAME CHAR(10),
ITEMID INTEGER);
EXEC SQL
CREATE TABLE STOCK
(MODEL SMALLINT NOT NULL UNIQUE,
MODELNAME CHAR(10) NOT NULL,
ITEMID INTEGER NOT NULL,
CONSTRAINT MOD_UNIQUE UNIQUE (MODELNAME, ITEMID));
See also
DELETE
Removes rows in a table or in the active set of a cursor. Available in gpre, DSQL,
and isql.
Syntax
Important
2-88
Argument
Description
TRANSACTION
transaction
table
WHERE search_condition
Language Reference
Argument
Description
WHERE CURRENT OF
cursor
ORDER BY order_list
ROWS value
[TO upper_value]
[BY step_value]
[PERCENT][WITH TIES]
DELETE specifies one or more rows to delete from a table or updatable view.
DELETE is one of the database privileges controlled by the GRANT and REVOKE
statements.
The TRANSACTION clause can be used in multiple transaction SQL applications to
specify which transaction controls the DELETE operation. The TRANSACTION clause
is not available in DSQL or isql.
For searched deletions, the optional WHERE clause can be used to restrict
deletions to a subset of rows in the table.
Important
Without a WHERE clause, a searched delete removes all rows from a table.
When performing a positioned delete with a cursor, the WHERE CURRENT OF clause
must be specified to delete one row at a time from the active set.
Examples
2-89
EXEC SQL
DECLARE SMALL_CITIES CURSOR FOR
SELECT CITY, STATE
FROM CITIES
WHERE POPULATION < :min_pop;
EXEC SQL
OPEN SMALL_CITIES;
EXEC SQL
FETCH SMALL_CITIES INTO :cityname, :statecode;
WHILE (!SQLCODE)
{EXEC SQL
DELETE FROM CITIES
WHERE CURRENT OF SMALL_CITIES;
EXEC SQL
FETCH SMALL_CITIES INTO :cityname, :statecode;}
EXEC SQL
CLOSE SMALL_CITIES;
See also
For more information about using cursors, see the Embedded SQL Guide.
DESCRIBE
Provides information about columns that are retrieved by a dynamic SQL (DSQL)
statement, or information about the dynamic parameters that statement passes.
Available in gpre.
Syntax
Description
OUTPUT
INPUT
statement
xsqlda
Description
2-90
Language Reference
Statement
Purpose
PREPARE
DESCRIBE
EXECUTE
EXECUTE IMMEDIATE
Separate DESCRIBE statements must be issued for input and output operations.
The INPUT keyword must be used to store dynamic parameter information.
Important
When using DESCRIBE for output, if the value returned in the sqld field in the
XSQLDA is larger than the sqln field, you must:
Allocate more storage space for XSQLVAR structures.
Reissue the DESCRIBE statement.
Note
Example
The same XSQLDA structure can be used for input and output if desired.
The following embedded SQL statement retrieves information about the output of a
SELECT statement:
EXEC SQL
DESCRIBE Q INTO xsqlda
The next embedded SQL statement stores information about the dynamic
parameters passed with a statement to be executed:
EXEC SQL
DESCRIBE INPUT Q2 USING SQL DESCRIPTOR xsqlda;
See also
For more information about DSQL programming and the XSQLDA, see the
Embedded SQL Guide.
DISCONNECT
Detaches an application from a database. Available in gpre.
2-91
Syntax
Description
Description
ALL|DEFAULT
dbhandle
Before using DISCONNECT, commit or roll back the transactions affecting the
database to be detached.
To reattach to a database closed with DISCONNECT, reopen it with a CONNECT
statement.
Examples
See also
DROP DATABASE
Deletes the currently attached database. Available in isql.
Syntax
Description
DROP DATABASE;
DROP DATABASE deletes the currently attached database, including any associated
secondary, shadow, and log files. Dropping a database deletes any data it
contains.
A database can be dropped by its creator, the SYSDBA user, and any users with
operating system root privileges.
Example
2-92
Language Reference
DROP DATABASE;
See also
DROP DOMAIN
Deletes a domain from a database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
If a domain is currently used in any column definition in the database, the DROP
operation fails. To prevent failure, use ALTER TABLE to delete the columns based on
the domain before executing DROP DOMAIN.
A domain may be dropped by its creator, the SYSDBA, and any users with operating
system root privileges.
Example
See also
DROP ENCRYPTION
Used to delete an encryption key from a database.
Syntax
Description
Description
key-name
An encryption key can be dropped (deleted) from the database. Only the SYSDSO
can execute this command. The command will fail if the encryption key is still being
used to encrypt the database or any table columns when the restrict option is
specified (which is the default drop behavior). If cascade is specified, then all
columns using that encryption are decrypted and the encryption is dropped.
Restrict and Cascade are the only options available for this command.
2-93
Example
The following example uses the cascade option to decrypt all columns using the
revenue_key and to delete the key:
drop encryption revenue_key cascade
See also
For more information about creating and dropping encryption keys and performing
encryption, see the Data Definition Guide.
DROP EXCEPTION
Deletes an exception from a database. Available in DSQL and isql.
Syntax
Description
Description
name
Example
See also
2-94
Description
name
Language Reference
Description
A UDF can be dropped by its declarer, the SYSDBA user, or any users with
operating system root privileges.
Example
See also
DROP FILTER
Removes a Blob filter declaration from a database. Available in gpre, DSQL, and
isql.
Syntax
Important
Description
Description
name
DROP FILTER removes a Blob filter declaration from a database. Dropping a Blob
filter declaration from a database does not remove it from the corresponding Blob
filter library, but it does make the filter inaccessible from the database. Once the
definition is dropped, any applications that depend on the filter will return run-time
errors.
DROP FILTER fails and returns an error if any processes are using the filter.
A filter can be dropped by its creator, the SYSDBA user, or any user with operating
system root privileges.
Example
See also
DECLARE FILTER
DROP GENERATOR
Drops a generator from the database. Available in DSQL, and isql.
Syntax
2-95
Description
Note
See also
Argument
Description
generator_name
This command checks for any existing dependencies on the generator (as in
triggers or UDFs) and fails if such dependencies exist. The statement fails if
generator_name is not the name of a generator defined on the database. An
application that tries to call a deleted generator returns runtime errors.
In previous versions of InterBase that lacked the DROP GENERATOR command,
users issued a SQL statement to delete the generator from the appropriate system
table. This approach is strongly discouraged now that the DROP GENERATOR
command is available, since modifying system tables always carries with it the
possibility of rendering the entire database unusable as a result of even a slight
error or miscalculation.
GEN_ID( ), CREATE GENERATOR, SET GENERATOR
DROP INDEX
Removes an index from a database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
An index can be dropped by its creator, the SYSDBA user, or any user with
operating system root privileges.
Important
You cannot drop system-defined indexes, such as those for UNIQUE, PRIMARY KEY,
and FOREIGN KEY.
An index in use is not dropped until it is no longer in use.
Example
See also
For more information about integrity constraints and system-defined indexes, see
the Data Definition Guide.
2-96
Language Reference
DROP JOURNAL
Discontinues the use of journaling and deletes existing journal files in the
database.
Syntax
Description
See also
DROP JOURNAL
The DROP JOURNAL statement discontinues the use of write-ahead logging and
deletes all journal files. This operation does not delete any journal files in the
journal archive but does discontinue maintenance of the journal archive. Dropping
journal files requires exclusive access to the database.
CREATE JOURNAL, CREATE JOURNAL ARCHIVE, DROP JOURNAL ARCHIVE
For more information about journaling, journal files, and journal archiving, see the
Operations Guide.
Important
See also
This command does not discontinue journaling and the creation of journal files.
CREATE JOURNAL ARCHIVE, DROP JOURNAL ARCHIVE, CREATE JOURNAL, DROP
JOURNAL.
For more information about journaling, journal files, and journal archiving, see the
Operations Guide..
DROP PROCEDURE
Deletes an existing stored procedure from a database. Available in DSQL, and
isql.
Syntax
Description
Description
name
database.
Procedures used by other procedures, triggers, or views cannot be dropped.
Procedures currently in use cannot be dropped.
2-97
Tip
Example
See also
DROP ROLE
Deletes a role from a database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
rolename
DROP ROLE deletes a role that was previously created using CREATE ROLE. Any
privileges that users acquired or granted through their membership in the role are
revoked.
A role can be dropped by its creator, the SYSDBA user, or any user with superuser
privileges.
Example
See also
DROP SHADOW
Deletes a shadow from a database. Available in gpre, DSQL, and isql.
Syntax
Important
2-98
Description
set_num
Language Reference
Description
DROP SHADOW deletes a shadow set and detaches from the shadowing process.
The isql SHOW DATABASE command can be used to see shadow set numbers for a
database.
A shadow can be dropped by its creator, the SYSDBA user, or any user with
operating system root privileges.
Example
The following isql statement deletes a shadow set from its database:
DROP SHADOW 1;
See also
CREATE SHADOW
DROP TABLE
Removes a table from a database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
DROP TABLE removes a tables data, metadata, and indexes from a database. It
also drops any triggers that reference the table.
When used to drop an external table, DROP TABLE only removes the table definition
from the database. The external file is not deleted.
A table can be dropped by its creator, the SYSDBA user, or any user with operating
system root privileges.
Example
See also
DROP TRIGGER
Deletes an existing user-defined trigger from a database. Available in DSQL and
isql.
Syntax
2-99
Description
Argument
Description
name
To inactivate a trigger temporarily, use ALTER TRIGGER and specify INACTIVE in the
header.
The following isql statement drops a trigger:
DROP TRIGGER POST_NEW_ORDER;
See also
DROP USER
Deletes an existing user from an embedded user authentication database.
Available in DSQL, and isql.
Syntax
DROP VIEW
Removes a view definition from the database. Available in gpre, DSQL, and isql.
Syntax
Important
Description
2-100
Description
name
DROP VIEW enables a views creator to remove a view definition from the database
if the view is not used in another view, stored procedure, or CHECK constraint
definition.
Language Reference
A view can be dropped by its creator, the SYSDBA user, or any user with operating
system root privileges.
Example
See also
CREATE VIEW
Example
The following embedded SQL statements declare a section, and single hostlanguage variable:
EXEC SQL
BEGIN DECLARE SECTION;
BASED_ON EMPLOYEE.SALARY salary;
EXEC SQL
END DECLARE SECTION;
See also
EVENT INIT
Registers interest in one or more events with the InterBase event manager.
Available in gpre.
Syntax
Description
request_name
dbhandle
string
:variable
2-101
Description
EVENT INIT is the first step in the InterBase two-part synchronous event
mechanism:
See also
For more information about events, see the Embedded SQL Guide.
EVENT WAIT
Causes an application to wait until notified of an events occurrence. Available in
gpre.
Syntax
Description
Description
request_name
EVENT WAIT is the second step in the InterBase two-part synchronous event
mechanism. After a program registers interest in an event, EVENT WAIT causes the
process running the application to sleep until the event of interest occurs.
Examples
The following embedded SQL statements register an application event name and
indicate the program is ready to receive notification when the event occurs:
EXEC SQL
EVENT INIT ORDER_WAIT EMPDB ('new_order');
EXEC SQL
EVENT WAIT ORDER_WAIT;
See also
2-102
EVENT INIT
Language Reference
For more information about events, see the Embedded SQL Guide.
EXECUTE
Executes a previously prepared dynamic SQL (DSQL) statement. Available in
gpre.
Syntax
Description
Description
TRANSACTION transaction
statement
xsqlda
Purpose
PREPARE
DESCRIBE
EXECUTE
EXECUTE IMMEDIATE
2-103
See also
For more information about DSQL programming and the XSQLDA, see the
Embedded SQL Guide.
EXECUTE IMMEDIATE
Prepares a dynamic SQL (DSQL) statement, executes it once, and discards it.
Available in gpre.
Syntax
2-104
Description
TRANSACTION transaction
:variable
string
xsqlda
Language Reference
Description
appropriate values.
Example
See also
For more information about DSQL programming and the XSQLDA, see the
Embedded SQL Guide.
EXECUTE PROCEDURE
Calls a stored procedure. Available in gpre, DSQL, and isql.
Syntax
SQL form:
2-105
Description
Argument
Description
TRANSACTION transaction
name
param
RETURNING_VALUES:
param
[INDICATOR] :indicator
Examples
See also
For more information about indicator variables, see the Embedded SQL Guide.
2-106
Language Reference
EXTRACT( )
Extracts date and time information from DATE, TIME, and TIMESTAMP values.
Available in gpre, DSQL, and isql.
Syntax
Description
part
Note
Example
Part extracted
Datatype
Range
YEAR
SMALLINT
05400
MONTH
SMALLINT
112
DAY
SMALLINT
131
HOUR
SMALLINT
023
MINUTE
SMALLINT
059
SECOND
DECIMAL(6,4)
059.9999
WEEKDAY
SMALLINT
06
(0 = Sunday, 1 = Monday, etc.)
YEARDAY
SMALLINT
0365
FETCH
Retrieves the next available row from the active set of an opened cursor. Available
in gpre and DSQL.
Syntax
SQL form:
2-107
FETCH cursor
[INTO :hostvar [[INDICATOR] :indvar]
[, :hostvar [[INDICATOR] :indvar] ]];
DSQL form:
Argument
Description
cursor
:hostvar
:indvar
xsqlda
Description
FETCH retrieves one row at a time into a program from the active set of a cursor.
The first FETCH operates on the first row of the active set. Subsequent FETCH
statements advance the cursor sequentially through the active set one row at a
time until no more rows are found and SQLCODE is set to 100.
A cursor is a one-way pointer into the ordered set of rows retrieved by the select
expression in the DECLARE CURSOR statement. A cursor enables sequential
access to retrieved rows. There are four related cursor statements:
2-108
Stage
Statement
Purpose
DECLARE CURSOR
OPEN
FETCH
Retrieve the current row from the active set, starting with
the first row; subsequent FETCH statements advance the
cursor through the set
CLOSE
Language Reference
The number, size, datatype, and order of columns in a FETCH must be the same as
those listed in the query expression of its matching DECLARE CURSOR statement. If
they are not, the wrong values can be assigned.
Examples
The following embedded SQL statement fetches a column from the active set of a
cursor:
EXEC SQL
FETCH PROJ_CNT INTO :department, :hcnt;
See also
For more information about cursors and XSQLDA, see the Embedded SQL Guide.
FETCH (BLOB)
Retrieves the next available segment of a Blob column and places it in the
specified local buffer. Available in gpre.
Syntax
Description
Description
cursor
:buffer
INDICATOR
:segment_length
FETCH retrieves the next segment from a Blob and places it into the specified
buffer.
The host variable, segment_length, indicates the number of bytes fetched. This is
useful when the number of bytes fetched is smaller than the host variable, for
example, when fetching the last portion of a Blob.
FETCH can return two SQLCODE values:
SQLCODE = 100 indicates that there are no more Blob segments to retrieve.
SQLCODE = 101 indicates that a partial segment was retrieved and placed in the
local buffer variable.
Note
To ensure that a host variable buffer is large enough to hold a Blob segment buffer
during FETCH operations, use the SEGMENT option of the BASED ON statement.
2-109
To ensure that a host variable buffer is large enough to hold a Blob segment buffer
during FETCH operations, use the SEGMENT option of the BASED ON statement.
Example
The following code, from an embedded SQL application, performs a BLOB FETCH:
while (SQLCODE != 100)
{
EXEC SQL
OPEN BLOB_CUR USING :blob_id;
EXEC SQL
FETCH BLOB_CUR INTO :blob_segment :blob_seg_len;
while (SQLCODE !=100 || SQLCODE == 101)
{
blob_segment{blob_seg_len + 1] = '\0';
printf("%*.*s",blob_seg_len,blob_seg_len,blob_segment);
blob_segment{blob_seg_len + 1] = ;
EXEC SQL
FETCH BLOB_CUR INTO :blob_segment :blob_seg_len;
}
. . .
}
See also
BASED ON, CLOSE (BLOB), DECLARE CURSOR (BLOB), INSERT CURSOR (BLOB), OPEN
(BLOB)
GEN_ID( )
Produces a system-generated integer value. Available in gpre, DSQL, and isql.
Syntax
Description
Description
generator
step
Note
2-110
Language Reference
Examples
See also
GRANT
Assigns privileges to users for specified database objects. Available in gpre,
DSQL, and isql.
Syntax
2-111
Important
Description
Description
privilege_list
col
tablename
viewname
GROUP unix_group
object
userlist
rolename
role_grantee_list
GRANT assigns privileges and roles for database objects to users, roles, or other
database objects. When an object is first created, only its creator has privileges to
it and only its creator can GRANT privileges for it to other users or objects.
Enables users to
ALL
SELECT
DELETE
2-112
Language Reference
Note
Privilege
Enables users to
DECRYPT
ENCRYPT ON
ENCRYPTION
INSERT
UPDATE
EXECUTE
REFERENCES
ALL does not include REFERENCES in code written for InterBase 4.0 or earlier.
2-113
Make it easy: if read security is not an issue, GRANT REFERENCES on the primary
key table to PUBLIC.
If you grant the REFERENCES privilege, it must, at a minimum, be granted to all
columns of the primary key. When REFERENCES is granted to the entire table,
columns that are not part of the primary key are not affected in any way.
When a user defines a foreign key constraint on a table owned by someone
else, InterBase checks that the user has REFERENCES privileges on the
referenced table.
The privilege is used at runtime to verify that a value entered in a foreign key
field is contained in the primary key table.
You can grant REFERENCES privileges to roles.
To give users permission to grant privileges to other users, provide a userlist
that includes the WITH GRANT OPTION. Users can grant to others only the
privileges that they themselves possess.
To grant privileges to all users, specify PUBLIC in place of a list of user names.
Specifying PUBLIC grants privileges only to users, not to database objects.
Privileges can be removed only by the user who assigned them, using REVOKE. If
ALL privileges are assigned, then ALL privileges must be revoked. If privileges are
granted to PUBLIC, they can be removed only for PUBLIC.
Examples
The following isql statement grants SELECT and DELETE privileges to a user. The
WITH GRANT OPTION gives the user GRANT authority.
GRANT SELECT, DELETE ON COUNTRY TO CHLOE WITH GRANT OPTION;
The next embedded SQL statement, from an embedded program, grants SELECT
and UPDATE privileges to a procedure for a table:
EXEC SQL
GRANT SELECT, UPDATE ON JOB TO PROCEDURE GET_EMP_PROJ;
This embedded SQL statement grants EXECUTE privileges for a procedure to
another procedure and to a user:
EXEC SQL
GRANT EXECUTE ON PROCEDURE GET_EMP_PROJ
TO PROCEDURE ADD_EMP_PROJ, LUIS;
The following example creates a role called administrator, grants UPDATE
privileges on table1 to that role, and then grants the role to user1, user2, and
user3. These users then have UPDATE and REFERENCES privileges on table1.
2-114
Language Reference
REVOKE
For more information about privileges, see the Data Definition Guide..
INSERT
Adds one or more new rows to a specified table. Available in gpre, DSQL, and isql.
Syntax
Description
expr
select_expr
A SELECT that returns zero or more rows and where the number of
columns in each row is the same as the number of items to be
inserted
In SQL and isql, you cannot use val as a parameter placeholder (like ?).
In DSQL and isql, val cannot be a variable.
You cannot specify a COLLATE clause for Blob columns.
Important
2-115
Argument
Description
TRANSACTION transaction
Description
INTO object
col
select_expr
INSERT stores one or more new rows of data in an existing table or view. INSERT is
one of the database privileges controlled by the GRANT and REVOKE statements.
Values are inserted into a row in column order unless an optional list of target
columns is provided. If the target list of columns is a subset of available columns,
default or NULL values are automatically stored in all unlisted columns.
If the optional list of target columns is omitted, the VALUES clause must provide
values to insert into all columns in the table.
To insert a single row of data, the VALUES clause should include a specific list of
values to insert.
To insert multiple rows of data, specify a select_expr that retrieves existing data
from another table to insert into this one. The selected columns must correspond
to the columns listed for insert.
Important
It is legal to select from the same table into which insertions are made, but this
practice is not advised because it may result in infinite row insertions.
The TRANSACTION clause can be used in multiple transaction SQL applications to
specify which transaction controls the INSERT operation. The TRANSACTION
clause is not available in DSQL or isql.
Examples
See also
2-116
Language Reference
Description
Description
cursor
VALUES
:buffer
INDICATOR
:bufferlen
INSERT CURSOR writes Blob data into a column. Data is written in units equal to or
less than the segment size for the Blob. Before inserting data into a Blob cursor:
INSERT CURSOR requires the INSERT privilege, a table privilege controlled by the
GRANT and REVOKE statements.
The following embedded SQL statement shows an insert into the Blob cursor:
EXEC SQL
INSERT CURSOR BC VALUES (:line INDICATOR :len);
See also
MAX( )
Retrieves the maximum value in a column. Available in gpre, DSQL, and isql.
Syntax
2-117
Description
Argument
Description
ALL
DISTINCT
val
MAX() is an aggregate function that returns the largest value in a specified column,
excluding NULL values. If the number of qualifying rows is zero, MAX() returns a
NULL value.
When MAX() is used on a CHAR, VARCHAR, or Blob text column, the largest value
returned varies depending on the character set and collation in use for the column.
A default character set can be specified for an entire database with the DEFAULT
CHARACTER SET clause in CREATE DATABASE, or specified at the column level with
the COLLATE clause in CREATE TABLE.
Example
The following embedded SQL statement demonstrates the use of SUM(), AVG(),
MIN(), and MAX():
EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX
(BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
See also
MIN( )
Retrieves the minimum value in a column. Available in gpre, DSQL, and isql.
Syntax
Description
2-118
Description
ALL
DISTINCT
val
MIN() is an aggregate function that returns the smallest value in a specified column,
excluding NULL values. If the number of qualifying rows is zero, MIN() returns a
NULL value.
Language Reference
When MIN() is used on a CHAR, VARCHAR, or Blob text column, the smallest value
returned varies depending on the character set and collation in use for the column.
Use the DEFAULT CHARACTER SET clause in CREATE DATABASE to specify a default
character set for an entire database, or the COLLATE clause in CREATE TABLE to
specify a character set at the column level.
Example
The following embedded SQL statement demonstrates the use of SUM(), AVG(),
MIN(), and MAX():
EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX
(BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
See also
NULLIF( )
The NULLIF function returns a null value if the arguments are equal, otherwise it
returns the value of the first argument.
Syntax
Description
Example
The following example demonstrates the use of CASE using the sample
employee.ib database:
select NULLIF(department, head_dept) from department
OPEN
Retrieve specified rows from a cursor declaration. Available in gpre and DSQL.
Syntax
SQL form:
2-119
Argument
Description
TRANSACTION transaction
cursor
USING DESCRIPTOR
xsqlda
Description
A cursor is a one-way pointer into the ordered set of rows retrieved by the SELECT
in a DECLARE CURSOR statement. It enables sequential access to retrieved rows in
turn. There are four related cursor statements:
Stag
e
Examples
Statement
Purpose
DECLARE
CURSOR
OPEN
FETCH
Retrieves the current row from the active set, starting with
the first row
Subsequent FETCH statements advance the cursor
through the set
CLOSE
See also
OPEN (BLOB)
Opens a previously declared Blob cursor and prepares it for read or insert.
Available in gpre.
Syntax
2-120
Language Reference
Description
Argument
Description
TRANSACTION
name
cursor
INTO | USING
blob_id
OPEN prepares a previously declared cursor for reading or inserting Blob data.
Depending on whether the DECLARE CURSOR statement declares a READ or
INSERT BLOB cursor, OPEN obtains the value for Blob ID differently:
For a READ BLOB, the blob_id comes from the outer TABLE cursor.
For an INSERT BLOB, the blob_id is returned by the system.
Examples
The following embedded SQL statements declare and open a Blob cursor:
EXEC SQL
DECLARE BC CURSOR FOR
INSERT BLOB PROJ_DESC INTO PRJOECT;
EXEC SQL
OPEN BC INTO :blob_id;
See also
PREPARE
Prepares a dynamic SQL (DSQL) statement for execution. Available in gpre.
Syntax
Description
TRANSACTION
transaction
2-121
Argument
Description
statement
INTO xsqlda
:variable | `string
execution.
Statement
Purpose
PREPARE
DESCRIBE
EXECUTE
EXECUTE IMMEDIATE
2-122
The DESCRIBE statement can be used instead of the INTO clause to fill in the XSQLDA
for a select list.
Language Reference
The FROM clause specifies the actual DSQL statement to PREPARE. It can be a
host-language variable, or a quoted string literal. The DSQL statement to PREPARE
can be any SQL data definition, data manipulation, or transaction-control
statement.
Examples
The following embedded SQL statement prepares a DSQL statement from a hostvariable statement. Because it uses the optional INTO clause, the assumption is
that the DSQL statement in the host variable is a SELECT.
EXEC SQL
PREPARE Q INTO xsqlda FROM :buf;
Note
The previous statement could also be prepared and described in the following
manner:
EXEC SQL
PREPARE Q FROM :buf;
EXEC SQL
DESCRIBE Q INTO SQL DESCRIPTOR xsqlda;
See also
RELEASE SAVEPOINT
Syntax
Description
See also
REVOKE
Withdraws privileges from users for specified database objects. Available in gpre,
DSQL, and isql.
REVOKE [GRANT OPTION FOR] privilege ON [TABLE] {tablename |
viewname}
FROM {object | userlist | rolelist | GROUP UNIX_group}
| EXECUTE ON PROCEDURE procname FROM {object | userlist}
| role_granted FROM {PUBLIC | role_grantee_list}};
privileges = ALL [PRIVILEGES] | privilege_list
privilege_list = {
SELECT
| DELETE
| INSERT
| ENCRYPT ON ENCRYPTION
| DECRYPT
| UPDATE [(col [, col ])]
| REFERENCES [(col [, col ])]
2-123
}[, privilege_list ]
object = {
PROCEDURE procname
| TRIGGER trigname
| VIEW viewname
| PUBLIC
}[, object ]
userlist = [USER] username [, [USER] username ]
rolelist = rolename [, rolename ]
role_granted = rolename [, rolename ]
role_grantee_list = [USER] username [, [USER] username ]
Important
Description
Description
privilege_list
col
tablename
viewname
GROUP unix_group
object
userlist
rolename
role_grantee_list
REVOKE removes privileges from users or other database objects. Privileges are
operations for which a user has authority. The following table lists SQL privileges:
2-124
Language Reference
ALL
SELECT
DELETE
DECRYPT
ENCRYPT ON
ENCRYPTION
INSERT
UPDATE
REFERENCES
EXECUTE
GRANT OPTION FOR revokes a users right to GRANT privileges to other users.
The following isql statement takes the SELECT privilege away from a user for a
table:
Chapter 2 SQL Statement and Function Reference
2-125
GRANT
ROLLBACK
Restores the database to its state prior to the start of the current transaction or
savepoint. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Argument
Description
TRANSACTION name
TO SAVEPOINT name
WORK
RELEASE
ends the transaction. It breaks the programs connection to the database and frees
system resources. Use RELEASE in the last ROLLBACK to close all open databases.
Wait until a program no longer needs the database to release system resources.
The TRANSACTION clause can be used in multiple-transaction SQL applications to
specify which transaction to roll back. If omitted, the default transaction is rolled
back. The TRANSACTION clause is not available in DSQL.
Note
Examples
RELEASE, available only in SQL, detaches from all databases after ending the
current transaction. In effect, this option ends database processing. RELEASE is
supported for backward compatibility with older versions of InterBase. The
preferred method of detaching is with DISCONNECT.
2-126
Language Reference
EXEC SQL
ROLLBACK TRANSACTION MYTRANS;
See also
COMMIT, DISCONNECT
For more information about controlling transactions, see the Embedded SQL
Guide.
SAVEPOINT
Syntax
Description
SAVEPOINT savepoint_name
A savepoint allows a transaction to be partially rolled back. Updates that are made
after a named savepoint is established can be rolled back by issuing a ROLLBACK
command of the following form:
ROLLBACK [TRANSACTION transaction_name] TO SAVEPOINT
savepoint_name;
If no transaction name is specified, the default transaction is used.
A savepoint name can be any valid SQL identifier. Savepoint names must be
unique within their atomic execution context. If you assign a name that is already in
use, the existing savepoint is released and the name is applied to the current
savepoint. An application, for example, is an execution context, as is each trigger
and stored procedure. Thus, if you have an application with several triggers, you
can have a savepoint named SV1 within the application and also within each
trigger and stored procedure.
See also
SELECT
Retrieves data from one or more tables. Available in gpre, DSQL, and isql.
Syntax
2-127
|
|
|
}
2-128
Language Reference
order_list =
{col | int} [COLLATE collation]
[ASC[ENDING] | DESC[ENDING]]
[, order_list ]
Argument
Description
expr
select_one
select_list
select_expr
Argument
Description
TRANSACTION transaction
{*|val [, val ]}
The asterisk (*) retrieves all columns for the specified tables
val [, val ] retrieves a list of specified columns, values, and
expressions
table
view
procedure
alias
joined_table
join_type
WHERE search_condition
2-129
Description
Argument
Description
COLLATE collation
HAVING search_condition
UNION [ALL]
PLAN plan_expr
plan_item
ORDER BY order_list
ROWS value
[TO upper_value]
[BY step_value]
[PERCENT][WITH
TIES]
FOR UPDATE
SELECT retrieves data from tables, views, or stored procedures. Variations of the
SELECT statement make it possible to:
Retrieve a single row, or part of a row, from a table. This operation is referred to
as a singleton select.
In embedded applications, all SELECT statements that occur outside the context
of a cursor must be singleton selects.
Retrieve multiple rows, or parts of rows, from a table.
2-130
Language Reference
When declaring arrays, you must include the outermost brackets, shown below
in bold. For example, the following statement creates a 5 by 5 two-dimensional
array of strings, each of which is 6 characters long:
my_array = varchar(6)[5,5]
Use the colon (:) to specify an array with a starting point other than 1. The
following example creates an array of integers that begins at 10 and ends at 20:
my_array = integer[20:30]
In SQL and isql, you cannot use val as a parameter placeholder (like ?).
In DSQL and isql, val cannot be a variable.
You cannot specify a COLLATE clause for Blob columns.
You cannot specify a GROUP BY clause for Blob and array columns.
Important
Examples
2-131
EXEC SQL
SELECT COUNT (*) INTO :cnt FROM COUNTRY
WHERE POPULATION > 5000000;
The next isql statement establishes a table alias in the SELECT clause and uses it
to identify a column in the WHERE clause:
SELECT C.CITY FROM CITIES C
WHERE C.POPULATION < 1000000;
The following isql statement selects two columns and orders the rows retrieved by
the second of those columns:
SELECT CITY, STATE FROM CITIES
ORDER BY STATE;
The next isql statement performs a left join:
SELECT CITY, STATE_NAME FROM CITIES C
LEFT JOIN STATES S ON S.STATE = C.STATE
WHERE C.CITY STARTING WITH 'San';
The following isql statement specifies a query optimization plan for ordered
retrieval, utilizing an index for ordering:
SELECT * FROM CITIES
PLAN (CITIES ORDER CITIES_1);
ORDER BY CITY
The next isql statement specifies a query optimization plan based on a three-way
join with two indexed column equalities:
SELECT * FROM CITIES C, STATES S, MAYORS M
WHERE C.CITY = M.CITY AND C.STATE = M.STATE
PLAN JOIN (STATE NATURAL, CITIES INDEX DUPE_CITY,
MAYORS INDEX MAYORS_1);
The next example queries two of the system tables, RDB$CHARACTER_SETS and
RDB$COLLATIONS to display all the available character sets, their ID numbers,
number of bytes per character, and collations. Note the use of ordinal column
numbers in the ORDER BY clause.
SELECT RDB$CHARACTER_SET_NAME, RDB$CHARACTER_SET_ID,
RDB$BYTES_PER_CHARACTER, RDB$COLLATION_NAME
FROM RDB$CHARACTER_SETS JOIN RDB$COLLATIONS
ON RDB$CHARACTER_SETS.RDB$CHARACTER_SET_ID =
RDB$COLLATIONS.RDB$CHARACTER_SET_IefD
ORDER BY 1, 4;
The following examples reward the best performing sales people and terminate
the least performing members of the sales team. The examples show how a Web
developer, for example, could split the result set in half for display purposes.
SELECT SALESMAN, SALES_DOLLARS, SALES_REGION
FROM SALESPEOPLE
2-132
Language Reference
SET DATABASE
Declares a database handle for database access. Available in gpre.
Syntax
Description
dbhandle
GLOBAL
STATIC
EXTERN
2-133
Description
Argument
Description
COMPILETIME
dbname
RUNTIME
:var
USER name
PASSWORD string
2-134
Language Reference
See also
For more information on the security database, see the Operations Guide.
SET GENERATOR
Sets a new value for an existing generator. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
int
SET GENERATOR initializes a starting value for a newly created generator, or resets
2-135
Generators return a 64-bit value, and wrap around only after 264 invocations
(assuming an increment of 1). Use an ISC-INT64 variable to hold the value returned
by a generator.
Tip
Important
Example
See also
SET NAMES
Specifies an active character set to use for subsequent database attachments.
Available in gpre, and isql.
Syntax
Important
Description
Description
charset
Name of a character set that identifies the active character set for a
given process; default: NONE
:var
SET NAMES specifies the character set to use for subsequent database
affect.
Tip
2-136
Language Reference
If you do not specify a default character set, the character set defaults to NONE.
Using character set NONE means that there is no character set assumption for
columns; data is stored and retrieved just as you originally entered it. You can load
any character set into a column defined with NONE, but you cannot load that same
data into another column that has been defined with a different character set. No
transliteration is performed between the source and destination character sets, so
in most cases, errors occur during assignment.
Example
The following statements demonstrate the use of SET NAMES in an embedded SQL
application:
EXEC SQL
SET NAMES ISO8859_1;
EXEC SQL
SET DATABASE DB1 = 'employee.ib';
EXEC SQL
CONNECT;
The next statements demonstrate the use of SET NAMES in isql:
SET NAMES LATIN1;
CONNECT 'employee.ib';
See also
For more information about character sets and collation orders, see the Data
Definition Guide.
Description
Description
SET SQL DIALECT declares the SQL Dialect for database access.
2-137
Examples
See also
SET STATISTICS
Recomputes the selectivity of a specified index. Available in gpre, DSQL, and isql.
Syntax
Important
Description
Description
name
SET STATISTICS does not rebuild an index. To rebuild an index, use ALTER INDEX.
Example
The following embedded SQL statement recomputes the selectivity for an index:
EXEC SQL
SET STATISTICS INDEX MINSALX;
See also
2-138
Language Reference
SET TRANSACTION
Starts a transaction and optionally specifies its behavior. Available in gpre, DSQL,
and isql.
Syntax
Important
Description
NAME transaction
READ WRITE
[Default] Specifies that the transaction can read and write to tables
READ ONLY
WAIT
NO WAIT
ISOLATION LEVEL
RESERVING
reserving_clause
USING dbhandle
[, dbhandle ]
2-139
Description
access, lock conflict behavior, and level of interaction with other concurrent
transactions accessing the same data. It can also reserve locks for tables. As an
alternative to reserving tables, multiple database SQL applications can restrict a
transactions access to a subset of connected databases.
Important
Applications preprocessed with the gpre -manual switch must explicitly start each
transaction with a SET TRANSACTION statement.
SET TRANSACTION affects the default transaction unless another transaction is
specified in the optional NAME clause. Named transactions enable support for
ensuring that transactions cannot write to tables, though they may still be able to
read from them.
READ COMMITTED enables a transaction to see the most recently committed
changes made by other simultaneous transactions. It can also update rows as long
as no update conflict occurs. Uncommitted changes made by other transactions
remain invisible until committed. READ COMMITTED also provides two optional
parameters:
NO RECORD_VERSION, the default, reads only the latest version of a row. If the
WAIT lock resolution option is specified, then the transaction waits until the latest
version of a row is committed or rolled back, and retries its read.
RECORD_VERSION reads the latest committed version of a row, even if more
recent uncommitted version also resides on disk.
The RESERVING clause enables a transaction to register its desired level of access
for specified tables when the transaction starts instead of when the transaction
attempts its operations on that table. Reserving tables at transaction start can
reduce the possibility of deadlocks.
2-140
Language Reference
The USING clause, available only in SQL, can be used to conserve system
resources by limiting the number of databases a transaction can access.
Examples
The following embedded SQL statement sets up the default transaction with an
isolation level of READ COMMITTED. If the transaction encounters an update
conflict, it waits to get control until the first (locking) transaction is committed or
rolled back.
EXEC SQL
SET TRANSACTION WAIT ISOLATION LEVEL READ COMMITTED;
The next embedded SQL statement starts a named transaction:
EXEC SQL
SET TRANSACTION NAME T1 READ COMMITTED;
The following embedded SQL statement reserves three tables:
EXEC SQL
SET TRANSACTION NAME TR1
ISOLATION LEVEL READ COMMITTED
NO RECORD_VERSION WAIT
RESERVING TABLE1, TABLE2 FOR SHARED WRITE,
TABLE3 FOR PROTECTED WRITE;
See also
For more information about transactions, see the Embedded SQL Guide.
Examples
SQL
Dialect
Used for
2-141
EXEC SQL
SHOW SQL DIALECT;
See also
SUM( )
Totals the numeric values in a specified column. Available in gpre, DSQL, and isql.
Syntax
Description
Example
Description
ALL
DISTINCT
val
SUM() is an aggregate function that calculates the sum of numeric values for a
column. If the number of qualifying rows is zero, SUM() returns a NULL value.
The following embedded SQL statement demonstrates the use of SUM(), AVG(),
MIN(), and MAX():
EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX
(BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
See also
UPDATE
Changes the data in all or part of an existing row in a table, view, or active set of a
cursor. Available in gpre, DSQL, and isql.
Syntax
SQL form:
2-142
Language Reference
In SQL and isql, you cannot use val as a parameter placeholder (like ?).
In DSQL and isql, val cannot be a variable.
You cannot specify a COLLATE clause for Blob columns.
Argument
Description
TRANSACTION transaction
table | view
WHERE search_condition
2-143
Argument
Description
WHERE CURRENT OF
cursor
Description
ORDER BY order_list
ROWS value
[TO upper_value]
[BY step_value]
[PERCENT][WITH TIES]
UPDATE modifies one or more existing rows in a table or view. UPDATE is one of the
database privileges controlled by GRANT and REVOKE.
For searched updates, the optional WHERE clause can be used to restrict updates
to a subset of rows in the table. Searched updates cannot update array slices.
Important
Note
Examples
When updating a Blob column, UPDATE replaces the entire Blob with a new value.
The following isql statement modifies a column for all rows in a table:
UPDATE CITIES
SET POPULATION = POPULATION * 1.03;
The next embedded SQL statement uses a WHERE clause to restrict column
modification to a subset of rows:
EXEC SQL
UPDATE PROJECT
SET PROJ_DESC = :blob_id
WHERE PROJ_ID = :proj_id;
See also
2-144
Language Reference
UPPER( )
Converts a string to all uppercase. Available in gpre, DSQL, and isql.
Syntax
UPPER (val)
Argume
nt
val
Description
A column, constant, host-language variable, expression, function,
or UDF that evaluates to a character datatype
Description
Examples
See also
CAST( )
WHENEVER
Traps SQLCODE errors and warnings. Available in gpre.
Syntax
Description
NOT FOUND
SQLERROR
SQLWARNING
GOTO label
CONTINUE
2-145
Description
WHENEVER traps for SQLCODE errors and warnings. Every executable SQL
statement returns a SQLCODE value to indicate its success or failure. If SQLCODE is
use a single suite of routines for handling all errors and warnings.
WHENEVER statements should precede any SQL statement that can result in an
error. Each condition to trap for requires a separate WHENEVER statement. If
WHENEVER is omitted for a particular condition, it is not trapped.
Tip
Example
2-146
Language Reference
Chapter
Chapter 3
3-1
For a trigger:
A table name, identifying the table that causes the trigger to fire.
Statements that determine when the trigger fires.
For a stored procedure:
An optional list of input parameters and their datatypes.
If the procedure returns values to the calling program, a list of output
parameters and their datatypes.
The body contains:
Nomenclature Conventions
This chapter uses the following nomenclature:
3-2
Language Reference
Assignment Statement
Assignment Statement
Assigns a value to an input or output parameter or local variable. Available in
triggers and stored procedures.
Syntax
Description
Example
variable = <expression>;
Argument
Description
variable
expression
See also
VARIABLE x INTEGER;
VARIABLE y INTEGER;
VARIABLE z INTEGER;
x;
x / (y - 6);
3-3
BEGIN END
BEGIN END
Defines a block of statements executed as one. Available in triggers and stored
procedures.
Syntax
Description
<block> =
BEGIN
<compound_statement>
[<compound_statement> ]
END
<compound_statement> = {<block> | statement;}
Each block of statements in the procedure body starts with a BEGIN statement and
ends with an END statement. As shown in the above syntax diagram, a block can
itself contain other blocks, so there may be many levels of nesting.
BEGIN and END are not followed by a semicolon. In isql, the final END in the
See also
3-4
Language Reference
Comment
Comment
Allows programmers to add comments to procedure and trigger code. Available in
triggers and stored procedures.
Syntax
Description
/* comment_text */
Argument
Description
comment_text
Example
The following isql procedure fragment illustrates some ways to use comments:
/*
*Procedure DELETE_EMPLOYEE : Delete an employee.
*
*Parameters:
* employee number
*Returns:
* -*/
CREATE PROCEDURE DELETE_EMPLOYEE (EMP_NUM INTEGER)
AS
DECLARE VARIABLE ANY_SALES INTEGER; /* Number of sales for
emp. /*
BEGIN
. . .
DECLARE VARIABLE
Declares a local variable. Available in triggers and stored procedures.
Syntax
Description
var
datatype
Data type of the local variable; can be any InterBase data type
except arrays
3-5
EXCEPTION
Description
Local variables are declared and used within a stored procedure. They have no
effect outside the procedure.
Local variables must be declared at the beginning of a procedure body before they
can be used. Each local variable requires a separate DECLARE VARIABLE
statement, followed by a semicolon (;).
Example
See also
EXCEPTION
Raises the specified exception. Available in triggers and stored procedures.
Syntax
Description
EXCEPTION name;
Argument
Description
name
Example
See also
3-6
WHEN DO
Language Reference
EXECUTE PROCEDURE
EXECUTE PROCEDURE
Executes a stored procedure. Available in triggers and stored procedures.
Syntax
Description
name
Description
[param [, param ]]
[RETURNING_VALUES
param [, param ]]
A stored procedure can itself execute a stored procedure. Each time a stored
procedure calls another procedure, the call is said to be nested because it occurs
in the context of a previous and still active call to the first procedure. A stored
procedure called by another stored procedure is known as a nested procedure.
If a procedure calls itself, it is recursive. Recursive procedures are useful for tasks
that involve repetitive steps. Each invocation of a procedure is referred to as an
instance, since each procedure call is a separate entity that performs as if called
from an application, reserving memory and stack space as required to perform its
tasks.
Note
Example
Stored procedures can be nested up to 1,000 levels deep. This limitation helps to
prevent infinite loops that can occur when a recursive procedure provides no
absolute terminating condition. Nested procedure calls may be restricted to fewer
than 1,000 levels by memory and stack limitations of the server.
The following example illustrates a recursive procedure, FACTORIAL, which
calculates factorials. The procedure calls itself recursively to calculate the
factorial of NUM, the input parameter.
CREATE PROCEDURE FACTORIAL (NUM INT)
RETURNS (N_FACTORIAL DOUBLE PRECISION)
AS
DECLARE VARIABLE NUM_LESS_ONE INT;
3-7
EXECUTE STATEMENT
BEGIN
IF (NUM = 1) THEN
BEGIN /**** Base case: 1 factorial is 1 ****/
N_FACTORIAL = 1;
EXIT;
END
ELSE
BEGIN
/**** Recursion: num factorial = num * (num-1) factorial
****/
NUM_LESS_ONE = NUM - 1;
EXECUTE PROCEDURE FACTORIAL NUM_LESS_ONE
RETURNING_VALUES N_FACTORIAL;
N_FACTORIAL = N_FACTORIAL * NUM;
EXIT;
END
END;
See also
EXECUTE STATEMENT
Embedding a variation of EXECUTE STATEMENTS within a Stored Procedure.
Description
See also
See also
For information on error messages added with the function, see Chapter 5: Error
Codes and Messages
3-8
Language Reference
::=
EXECUTE STATEMENT
Examples
Example
Example
3-9
FOR SELECTDO
IF (IFIELD = 0) THEN
INT_RETVAR = 0;
ELSE
INT_RETVAR = INT_RETVAR + IFIELD;
SUSPEND;
END
FOR SELECTDO
Repeats a block or statement for each row retrieved by the SELECT statement.
Available in triggers and stored procedures.
Syntax
Description
3-10
FOR <select_expr>
DO <compound_statement>
Argument
Description
select_expr
compound_statement
FOR SELECT is a loop statement that retrieves the row specified in the select_expr
and performs the statement or block following DO for each row retrieved.
Language Reference
IFTHEN ELSE
The select_expr is a normal SELECT, except the INTO clause is required and must
be the last clause.
Example
The following isql statement selects department numbers into the local variable,
RDNO, which is then used as an input parameter to the DEPT_BUDGET procedure:
FOR SELECT DEPT_NO
FROM DEPARTMENT
WHERE HEAD_DEPT = :DNO
INTO :RDNO
DO
BEGIN
EXECUTE PROCEDURE DEPT_BUDGET :RDNO RETURNING_VALUES
:SUMB;
TOT = TOT + SUMB;
END
See also
SELECT
IFTHEN ELSE
Conditional statement that performs a block or statement in the IF clause if the
specified condition is TRUE, otherwise performs the block or statement in the
optional ELSE clause. Available in triggers and stored procedures.
Syntax
IF (<condition>)
THEN <compound_statement>
[ELSE <compound_statement>]
Argument
condition
Description
Boolean expression that evaluates to TRUE, FALSE, or
UNKNOWN; must be enclosed in parentheses
THEN
compound_statement
ELSE
compound_statement
Description
Example
The following lines of code illustrate the use of IF THEN, assuming the variables
LINE2, FIRST, and LAST have been previously declared:
3-11
Input Parameters
. . .
IF (FIRST IS NOT NULL) THEN
LINE2 = FIRST || ' ' || LAST;
ELSE
LINE2 = LAST;
. . .
See also
WHILE DO
Input Parameters
Used to pass values from an application to a stored procedure. Available in stored
procedures only.
Syntax
Description
Example
The following procedure header, from an isql script, declares two input parameters,
EMP_NO and PROJ_ID:
CREATE PROCEDURE ADD_EMP_PROJ (EMP_NO SMALLINT, PROJ_ID
CHAR(5))
AS
. . .
See also
DECLARE VARIABLE
3-12
NEW.column
Language Reference
Description
Argument
Description
column
Triggers support two context variables: OLD and NEW. A NEW context variable
refers to the new value of a column in an INSERT or UPDATE operation.
Context variables are often used to compare the values of a column before and
after it is modified. Context variables can be used anywhere a regular variable can
be used.
New values for a row can only be altered before actions. A trigger that fires after
INSERT and tries to assign a value to NEW.column will have no effect. However,
the actual column values are not altered until after the action, so triggers that
reference values from their target tables will not see a newly inserted or updated
value unless they fire after UPDATE or INSERT.
Example
The following script is a trigger that fires after the EMPLOYEE table is updated, and
compares an employees old and new salary. If there is a change in salary, the
trigger inserts an entry in the SALARY_HISTORY table.
CREATE TRIGGER SAVE_SALARY_CHANGE FOR EMPLOYEE
AFTER UPDATE AS
BEGIN
IF (OLD.SALARY <> NEW.SALARY) THEN
INSERT INTO SALARY_HISTORY
(EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY,
PERCENT_CHANGE)
VALUES (OLD.EMP_NO, 'NOW', USER, OLD.SALARY,
(NEW.SALARY - OLD.SALARY) * 100 / OLD.SALARY);
END ;
See also
For more information on creating triggers, see CREATE TRIGGER on page 2-71.
OLD.column
Argument
Description
column
3-13
Output Parameters
Description
Triggers support two context variables: OLD and NEW. An OLD context variable
refers to the current or previous value of a column in an INSERT or UPDATE
operation.
Context variables are often used to compare the values of a column before and
after it is modified. Context variables can be used anywhere a regular variable can
be used.
Example
The following script is a trigger that fires after the EMPLOYEE table is updated, and
compares an employees old and new salary. If there is a change in salary, the
trigger inserts an entry in the SALARY_HISTORY table.
CREATE TRIGGER SAVE_SALARY_CHANGE FOR EMPLOYEE
AFTER UPDATE AS
BEGIN
IF (OLD.SALARY <> NEW.SALARY) THEN
INSERT INTO SALARY_HISTORY
(EMP_NO, CHANGE_DATE, UPDATER_ID, OLD_SALARY,
PERCENT_CHANGE)
VALUES (OLD.EMP_NO, NOW, USER, OLD.SALARY,
(NEW.SALARY - OLD.SALARY) * 100 / OLD.SALARY);
END ;
See also
For more information about creating triggers, see CREATE TRIGGER on page
2-71.
Output Parameters
Used to return values from a stored procedure to the calling application. Available
in stored procedures only.
Syntax
Description
3-14
Language Reference
POST_EVENT
The following isql script is a procedure header declares five output parameters,
HEAD_DEPT, DEPARTMENT, MNGR_NAME, TITLE, and EMP_CNT:
CREATE PROCEDURE ORG_CHART RETURNS (HEAD_DEPT CHAR(25),
DEPARTMENT
CHAR(25), MNGR_NAME CHAR(20), TITLE CHAR(5), EMP_CNT
INTEGER)
See also
POST_EVENT
Posts an event. Available in triggers and stored procedures.
Syntax
Description
Example
Description
event_name
col
variable
POST_EVENT posts an event to the event manager. When an event occurs, this
statement will notify the event manager, which alerts applications waiting for the
named event.
3-15
SELECT
See also
SELECT
Retrieves a single row that satisfies the requirements of the search condition. The
same as standard singleton SELECT, with some differences in syntax. Available in
triggers and stored procedures.
<select_expr> = <select_clause> <from_clause>
[<where_clause>] [<group_by_clause>]
[<having_clause>]
[<union_expression>] [<plan_clause>]
[<ordering_clause>]
<into_clause>;
Description
In a stored procedure, use the SELECT statement with an INTO clause to retrieve a
single row value from the database and assign it to a host variable. The SELECT
statement must return at most one row from the database, like a standard
singleton SELECT. The INTO clause is required and must be the last clause in the
statement.
The INTO clause comes at the end of the SELECT statement to allow the use of
UNION operators. UNION is not allowed in singleton SELECT statements in
embedded SQL.
Example
See also
FOR SELECTDO
For a complete explanation of the standard SELECT syntax, see SELECT on page
2-127.
3-16
Language Reference
SUSPEND
SUSPEND
Suspends execution of a select procedure until the next FETCH is issued and
returns values to the calling application. Available in stored procedures only.
Syntax
Description
SUSPEND;
The SUSPEND statement:
Suspends execution of a stored procedure until the application issues the next
FETCH.
Returns values of output parameters, if any.
A procedure should ensure that all output parameters are assigned values before
a SUSPEND.
SUSPEND should not be used in an executable procedure. Use EXIT instead to
indicate to the reader explicitly that the statement terminates the procedure.
The following table summarizes the behavior of SUSPEND, EXIT, and END.
Table 3.1 SUSPEND, EXIT, and END
Note
Procedure type
SUSPEND
Select procedure
Jumps to final
Suspends execution
END
of procedure until
next FETCH is issued
Returns output
values
Executable
procedure
EXIT
Jumps to final
END
END
Returns control to
application
Sets SQLCODE to 100 (end
of record stream)
Returns values
Returns control to
application
Example
3-17
WHEN DO
WHILE (R < 5) DO
BEGIN
R = R + 1;
SUSPEND;
IF (R = 3) THEN
EXIT;
END
END;
If this procedure is used as a select procedure in isql, for example,
SELECT * FROM P;
then it will return values 1, 2, and 3 to the calling application, since the SUSPEND
statement returns the current value of r to the calling application until r = 3, when
the procedure performs an EXIT and terminates.
If the procedure is used as an executable procedure in isql, for example,
EXECUTE PROCEDURE P;
then it will return 1, since the SUSPEND statement will terminate the procedure and
return the current value of r to the calling application. Since SUSPEND should not
be used in executable procedures, EXIT would be used instead, indicating that
when the statement is encountered, the procedure is exited.
See also
WHEN DO
Error-handling statement that performs the statements following DO when the
specified error occurs. Available in triggers and stored procedures.
Syntax
Description
EXCEPTION
exception_name
SQLCODE number
3-18
Language Reference
WHEN DO
Important
Description
Argument
Description
GDSCODE errcode
ANY
compound_statement
If used, WHEN must be the last statement in a BEGINEND block. It should come
after SUSPEND, if present.
Procedures can handle three kinds of errors with a WHEN statement:
Exceptions raised by EXCEPTION statements in the current procedure, in a
nested procedure, or in a trigger fired as a result of actions by such a procedure.
SQL errors reported in SQLCODE.
InterBase error codes.
The WHEN ANY statement handles any of the three types.
Handling Exceptions
Instead of terminating when an exception occurs, a procedure can respond to and
perhaps correct the error condition by handling the exception. When an exception
is raised, it:
Terminates execution of the BEGIN END block containing the exception and
undoes any actions performed in the block.
Backs out one level to the next BEGIN END block and seeks an exceptionhandling (WHEN) statement, and continues backing out levels until one is found.
If no WHEN statement is found, the procedure is terminated and all its actions
are undone.
Performs the ensuing statement or block of statements specified after WHEN, if
found.
Returns program control to the block or statement in the procedure following the
WHEN statement.
Note
An exception that is handled with WHEN does not return an error message.
3-19
WHEN DO
See also
EXCEPTION
For more information about InterBase error codes and SQLCODE values, see
Chapter 5, Error Codes and Messages.
3-20
Language Reference
WHILE DO
WHILE DO
Performs the statement or block following DO as long as the specified condition is
TRUE. Available in triggers and stored procedures.
Syntax
Description
WHILE (<condition>) DO
<compound_statement>
Argument
Description
condition
compound_statement
as long as a condition is true. The condition is tested at the start of each loop.
Example
The following procedure, from an isql script, uses a WHILE DO loop to compute
the sum of all integers from one up to the input parameter:
CREATE PROCEDURE SUM_INT (I INTEGER) RETURNS (S INTEGER)
AS
BEGIN
S = 0;
WHILE (I > 0) DO
BEGIN
S = S + I;
I = I - 1;
END
END;
If this procedure is called from isql with the command:
EXECUTE PROCEDURE SUM_INT 4;
then the results will be:
S
==========
10
See also
3-21
WHILE DO
3-22
Language Reference
Chapter
Keywords
Chapter 4
The table in this chapter lists keywords, words reserved from use in SQL programs
and isql (Interactive SQL). The list includes DSQL, isql, and gpre keywords.
Keywords are defined for special purposes, and are sometimes called reserved
words. A keyword cannot occur in a user-declared identifier or as the name of a
table, column, index, trigger, or constraint, unless it is enclosed in double quotes.
Keywords are:
Part of statements
Used as statements
Names of standard data structures or datatypes
InterBase Keywords
ACTION
ACTIVE
ADD
ADMIN
AFTER
ALL
ALTER
AND
ANY
AS
ASC
ASCENDING
AT
AUTO
AUTODDL
AVG
BASED
BASENAME
BASE_NAME
BEFORE
BEGIN
BETWEEN
BLOB
BLOBEDIT
BOOLEAN
BUFFER
BY
CACHE
CASCADE
CASE
CAST
CHAR
CHARACTER
CHARACTER_LENGTH
CHAR_LENGTH
CHECK
Chapter 4 Keywords
4-1
InterBase Keywords
CHECK_POINT_LEN
CHECK_POINT_LENGTH
COALESCE
COLLATE
COLLATION
COLUMN
COMMIT
COMMITTED
COMPILETIME
COMPUTED
CLOSE
CONDITIONAL
CONNECT
CONSTRAINT
CONTAINING
CONTINUE
COUNT
CREATE
CSTRING
CURRENT
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAM
P
CURSOR
DATABASE
DATE
DAY
DB_KEY
DEBUG
DEC
DECIMAL
DECLARE
DECRYPT
DEFAULT
DELETE
DESC
DESCENDING
DESCRIBE
DESCRIPTOR
DISCONNECT
DISPLAY
DISTINCT
DO
DOMAIN
DOUBLE
DROP
ECHO
EDIT
ELSE
ENCRYPT
ENCRYPTION
END
ENTRY_POINT
ESCAPE
EVENT
EXCEPTION
EXECUTE
EXISTS
EXIT
EXTERN
EXTERNAL
EXTRACT
FALSE
FETCH
FILE
FILTER
FLOAT
FOR
FOREIGN
FOUND
FREE_IT
FROM
FULL
FUNCTION
GDSCODE
GENERATOR
GEN_ID
GLOBAL
GOTO
GRANT
GROUP
GROUP_COMMIT_WAIT
GROUP_COMMIT_WAI
T_TIME
HAVING
HELP
HOUR
IF
IMMEDIATE
IN
INACTIVE
INDEX
INDICATOR
INIT
INNER
INPUT
INPUT_TYPE
INSERT
INT
INTEGER
INTO
IS
ISOLATION
ISQL
JOIN
KEY
LC_MESSAGES
LC_TYPE
LEFT
LENGTH
LEV
LEVEL
LIKE
4-2
Language Reference
InterBase Keywords
LOGFILE
LOG_BUFFER_SIZE
LOG_BUF_SIZE
LONG
MANUAL
MAX
MAXIMUM
MAXIMUM_SEGMENT
MAX_SEGMENT
MERGE
MESSAGE
MIN
MINIMUM
MINUTE
MODULE_NAME
MONTH
NAMES
NATIONAL
NATURAL
NCHAR
NO
NOAUTO
NOT
NULL
NULLIF
NUMERIC
NUM_LOG_BUFS
NUM_LOG_BUFFERS
OCTET_LENGTH
OF
ON
ONLY
OPEN
OPTION
OR
ORDER
OUTER
OUTPUT
OUTPUT_TYPE
OVERFLOW
PAGE
PAGELENGTH
PAGES
PAGE_SIZE
PARAMETERS
PASSWORD
PERCENT
PLAN
POSITION
POST_EVENT
PRECISION
PREPARE
PRESERVE
PROCEDURE
PROTECTED
PRIMARY
PRIVILEGES
PUBLIC
QUIT
RAW_PARTITIONS
RDB$DB_KEY
READ
REAL
RECORD_VERSION
REFERENCES
RELEASE
RESERV
RESERVING
RESTRICT
RETAIN
RETURN
RETURNING_VALUES
RETURNS
REVOKE
RIGHT
ROLE
ROLLBACK
ROWS
RUNTIME
SCHEMA
SECOND
SEGMENT
SELECT
SET
SHADOW
SHARED
SHELL
SHOW
SINGULAR
SIZE
SMALLINT
SNAPSHOT
SOME
SORT
SQLCODE
SQLERROR
SQLWARNING
STABILITY
STARTING
STARTS
STATEMENT
STATIC
SUSPEND
TABLE
TEMPORARY
TERMINATOR
THEN
TIES
TIME
TIMESTAMP
TO
TRANSACTION
TRANSLATE
TRANSLATION
TRIGGER
Chapter 4 Keywords
4-3
InterBase Keywords
TRIM
TRUE
TYPE
UNCOMMITTED
UNION
UNIQUE
UNKNOWN
UPDATE
UPPER
USER
USING
VALUE
VALUES
VARCHAR
VARIABLE
VARYING
VERSION
VIEW
WAIT
WEEKDAY
WHEN
WHENEVER
WHERE
WHILE
WITH
WORK
WRITE
YEAR
YEARDAY
Note
The following keywords are specific to InterBase and are not part of the SQL
standard:
WEEKDAY
4-4
Language Reference
YEARDAY
Chapter
Chapter 5
This chapter summarizes InterBase error-handling options and error codes. Tables
in this chapter list SQLCODE and InterBase error codes and messages for
embedded SQL, dynamic SQL (DSQL), and interactive SQL (isql). For a detailed
discussion of error handling, see the Embedded SQL Statement.
Error Sources
Run-time errors occur at points of user input or program output. When you run a
program or use isql, the following types of errors may occur:
Error type
Description
Action
Database error
Bugcheck or
internal error
5-1
5-2
Language Reference
When SQLCODE < 0, this function prints the returned SQLCODE value, the
corresponding SQL error message, and any additional InterBase error messages
in the status array to the screen. Use within an error-handling routine.
Syntax
This function retrieves a SQL error message and stores it in a user-supplied buffer
for later printing, manipulation, or display. Allow a buffer length of 256 bytes to hold
the message. Use when building error display routines or if you are using a
windowing system that does not permit direct screen writes. Do not use this
function when SQLCODE > 0.
Syntax
5-3
For the following errors, it is recommended that you roll back the current
transaction and try the operation again:
Table 5.1 Status array codes that require rollback and retry
Status array
code
Action to take
isc_convert_erro
r
isc_deadlock
isc_integ_fail
isc_lock_conflict
isc_no_dup
isc_not_valid
Validation error: Row did not pass validation test; correct invalid row
and try again
To find
See
SQLCODE and
error handling
List of SQLCODEs
WHENEVER syntax
Programming
InterBase status
array and
functions
WHENEVER
5-4
Language Reference
Message
Meaning
<0
SQLERROR
SUCCESS
Successful completion
+199
SQLWARNING
+100
NOT FOUND
5-5
SQLCODE text
InterBase
number
101
335544366L
100
335544338L
100
335544354L
100
335544367L
100
335544374L
-84
335544554L
-84
335544555L
-84
335544668L
-103
335544571L
-104
335544343L
-104
335544390L
-104
335544425L
-104
335544426L
-104
335544429L
-104
5-6
335544440L
-104
335544456L
-104
Invalid command
335544570L
-104
Internal error
335544579L
-104
335544590L
-104
335544591L
-104
335544592L
-104
335544634L
-104
335544608L
-104
Token unknown
335544612L
-150
335544360L
-150
335544362L
Language Reference
SQLCODE text
InterBase
number
-150
Not updatable
335544446L
-150
335544546L
-151
335544359L
-155
335544658L
-157
335544598L
-158
335544599L
-162
335544685L
-170
335544512L
-170
335544619L
-171
335544439L
-171
335544458L
-171
335544618L
-172
335544438L
-204
335544463L
-204
336003096L
-204
335544502L
-204
335544509L
-204
335544511L
-204
335544515L
-204
335544516L
-204
335544532L
-204
335544551L
-204
335544568L
-204
Datatype unknown
335544573L
-204
Table unknown
335544580L
-204
Procedure unknown
335544581L
5-7
5-8
SQLCODE
SQLCODE text
InterBase
number
-204
335544588L
-204
335544589L
-204
Trigger unknown
335544595L
-204
335544620L
-204
335544621L
-204
335544622L
-204
335544635L
-204
335544636L
-204
335544640L
-204
335544662L
-204
335544850
-204
335544851
-204
335544852
-204
335544853
-204
335544854
-204
335544855
-204
335544857
-204
335544858
-205
335544396L
-205
335544552L
-206
Column unknown
335544578L
-206
335544587L
-206
335544596L
Language Reference
SQLCODE text
InterBase
number
-208
335544617L
-219
335544395L
-239
335544691L
-260
Cache redefined
335544690L
-281
335544637L
-282
335544638L
-282
335544643L
-282
335544659L
-282
View <string> has more than one base table; use aliases
to distinguish
335544660L
-283
335544639L
-284
335544642L
-291
335544531L
-292
335544534L
-293
335544535L
-294
335544536L
-295
335544545L
-296
335544547L
-297
335544558L
-313
335544669L
-314
335544565L
-401
335544647L
5-9
5-10
SQLCODE
SQLCODE text
InterBase
number
-402
335544368L
-402
335544414L
-402
335544427L
-406
335544457L
-407
335544435L
-413
335544334L
-413
335544454L
-501
335544327L
-501
335544577L
-502
335544574L
-502
335544576L
-504
Cursor unknown
335544572L
-508
335544348L
-510
335544575L
-518
Request unknown
335544582L
-519
335544688L
-530
335544466L
-530
335544597L
-532
335544469L
-551
335544352L
-552
335544550L
-552
335544553L
-553
335544529L
-595
335544645L
-596
335544644L
Language Reference
SQLCODE
SQLCODE text
-597
335544632L
-598
335544633L
-599
335544607L
-600
335544625L
-600
335544680L
-601
335544646L
-604
335544593L
-604
335544594L
-605
335544682L
-607
335544351L
-607
335544549L
-607
335544657L
-615
335544475L
-615
335544476L
-615
335544507L
-616
335544530L
-616
335544539L
-616
335544540L
-616
335544541L
-616
335544543L
-616
335544630L
-616
335544674L
-617
335544542L
-617
335544544L
5-11
SQLCODE
SQLCODE text
-618
335544537L
-618
335544538L
-625
335544347L
-637
335544664L
-660
335544533L
FOREIGN KEY
5-12
-660
335544628L
-663
335544624L
-663
335544631L
-663
335544672L
-664
335544434L
-677
335544445L
-685
335544465L
-685
335544670L
-685
335544671L
-689
335544403L
-689
335544650L
-690
335544679L
-691
335544681L
-692
335544477L
-693
335544663L
-694
335544684L
-802
335544321L
-803
335544349L
Language Reference
SQLCODE
SQLCODE text
-803
335544665L
-804
335544380L
-804
335544583L
type of variables
-804
335544584L
-804
Function unknown
335544586L
335544600L
-806
CHECK OPTION
-807
335544601L
-808
335544602L
-809
335544603L
-810
335544605L
-811
335544652L
-816
335544651L
-817
335544361L
-817
335544371L
-817
335544444L
-820
Metadata is obsolete
335544356L
-820
335544379L
-820
335544437L
-820
335544467L
-823
335544473L
-824
335544474L
-825
335544519L
-826
335544585L
-827
335544655L
5-13
5-14
SQLCODE
SQLCODE text
InterBase
number
-828
335544678L
-829
335544616L
-830
335544615L
-831
335544548L
-832
335544604L
-833
335544606L
-834
335544508L
-835
Bad checksum
335544649L
-836
Exception <digit>
335544517L
-837
335544518L
-838
335544560L
-839
335544686L
-840
335544687L
-841
335544677L
-842
335544697L
-842
335544698L
-842
335544699L
-842
335544700L
-842
335544701L
-901
335544322L
-901
335544326L
-901
335544328L
-901
Invalid Blob ID
335544329L
-901
335544330L
-901
335544331L
Language Reference
SQLCODE
SQLCODE text
-901
335544332L
-901
335544337L
-901
335544339L
-901
335544340L
-901
335544341L
-901
335544342L
-901
335544345L
-901
335544350L
-901
335544353L
-901
335544355L
-901
335544357L
-901
335544358L
-901
335544363L
-901
335544364L
-901
335544365L
-901
335544369L
-901
335544370L
-901
335544372L
-901
335544376L
-901
335544377L
-901
335544378L
-901
<string>
335544382L
-901
335544383L
-901
Internal error
335544392L
5-15
5-16
SQLCODE
SQLCODE text
InterBase
number
-901
335544407L
-901
335544408L
-901
Transaction in limbo
335544418L
-901
335544419L
-901
Transaction outstanding
335544420L
-901
335544428L
-901
335544431L
-901
335544442L
-901
335544443L
-901
<string>
335544450L
-901
335544468L
-901
335544485L
-901
335544510L
-901
335544559L
-901
335544561L
-901
335544562L
-901
335544563L
-901
INDEX <string>
335544609L
-901
EXCEPTION <string>
335544610L
-901
Column <string>
335544611L
-901
335544613L
-901
335544614L
-901
335544623L
-901
Table <string>
335544626L
-901
Procedure <string>
335544627L
-901
335544641L
Language Reference
SQLCODE
SQLCODE text
-901
335544656L
-901
335544666L
-901
Cannot delete
335544673L
-901
Sort error
335544675L
-902
335544333L
-902
335544335L
-902
335544344L
-902
335544346L
-902
335544373L
-902
Internal error
335544384L
-902
Internal error
335544385L
-902
Internal error
335544387L
-902
335544388L
-902
335544394L
-902
Internal error
335544397L
-902
Internal error
335544398L
-902
Internal error
335544399L
-902
Internal error
335544400L
-902
Internal error
335544401L
-902
Internal error
335544402L
-902
Database corrupted
335544404L
-902
335544405L
-902
Index is broken
335544406L
-902
335544409L
-902
335544410L
-902
335544411L
5-17
5-18
InterBase
number
SQLCODE
SQLCODE text
-902
335544412L
-902
335544413L
-902
Database corrupted
335544415L
-902
Internal error
335544416L
-902
Internal error
335544417L
-902
Internal error
335544422L
-902
Internal error
335544423L
-902
335544432L
-902
335544436L
-902
335544448L
-902
335544449L
-902
335544470L
-902
335544471L
-902
Your user name and password are not defined. Ask your
database administrator to set up an InterBase login.
335544472L
-902
335544478L
-902
335544479L
-902
335544480L
-902
335544481L
-902
335544483L
-902
335544506L
-902
335544520L
-902
335544528L
-902
335544557L
-902
335544653L
-902
335544654L
Language Reference
SQLCODE text
InterBase
number
-902
335544564L
-902
335544569L
-904
335544324L
-904
Unavailable database
335544375L
-904
335544381L
-904
335544386L
-904
Buffer exhausted
335544389L
-904
Buffer in use
335544391L
-904
Request in use
335544393L
-904
335544424L
-904
335544430L
-904
335544451L
-904
335544453L
-904
335544455L
-904
335544460L
-904
335544661L
-904
335544676L
-904
335544683L
-904
335544762L
-906
335544452L
-909
335544667L
-911
335544459L
-913
Deadlock
335544336L
-922
335544323L
-923
335544421L
-923
335544461L
-923
335544462L
5-19
SQLCODE text
InterBase
number
-924
335544325L
-924
335544441L
-924
335544648L
-926
No rollback performed
335544447L
-999
InterBase error
335544689L
5-20
Error code
Number
Message
isc_arith_except
335544321L
isc_bad_dbkey
335544322L
isc_bad_db_format
335544323L
isc_bad_db_handle
335544324L
isc_bad_dpb_content
335544325L
isc_bad_dpb_form
335544326L
isc_bad_req_handle
335544327L
Language Reference
Number
Message
isc_bad_segstr_handle
335544328L
isc_bad_segstr_id
335544329L
invalid Blob ID
isc_bad_tpb_content
335544330L
isc_bad_tpb_form
335544331L
isc_bad_trans_handle
335544332L
isc_bug_check
335544333L
isc_convert_error
335544334L
isc_db_corrupt
335544335L
isc_deadlock
335544336L
deadlock
isc_excess_trans
335544337L
isc_from_no_match
335544338L
isc_infinap
335544339L
isc_infona
335544340L
isc_infunk
335544341L
isc_integ_fail
335544342L
isc_invalid_blr
335544343L
isc_io_error
335544344L
isc_lock_conflict
335544345L
isc_metadata_corrupt
335544346L
isc_not_valid
335544347L
isc_no_cur_rec
335544348L
5-21
5-22
Error code
Number
Message
isc_no_dup
335544349L
isc_no_finish
335544350L
isc_no_meta_update
335544351L
isc_no_priv
335544352L
isc_no_recon
335544353L
isc_no_record
335544354L
isc_no_segstr_close
335544355L
isc_obsolete_metadata
335544356L
metadata is obsolete
isc_open_trans
335544357L
isc_port_len
335544358L
isc_read_only_field
335544359L
isc_read_only_rel
335544360L
isc_read_only_trans
335544361L
isc_read_only_view
335544362L
isc_req_no_trans
335544363L
isc_req_sync
335544364L
isc_req_wrong_db
335544365L
isc_segment
335544366L
isc_segstr_eof
335544367L
isc_segstr_no_op
335544368L
isc_segstr_no_read
335544369L
Language Reference
Number
Message
isc_segstr_no_trans
335544370L
isc_segstr_no_write
335544371L
isc_segstr_wrong_db
335544372L
isc_sys_request
335544373L
isc_stream_eof
335544374L
isc_unavailable
335544375L
unavailable database
isc_unres_rel
335544376L
isc_uns_ext
335544377L
isc_wish_list
335544378L
isc_wrong_ods
335544379L
isc_wronumarg
335544380L
isc_imp_exc
335544381L
isc_random
335544382L
<string>
isc_fatal_conflict
335544383L
isc_badblk
335544384L
internal error
isc_invpoolcl
335544385L
internal error
isc_nopoolids
335544386L
isc_relbadblk
335544387L
internal error
isc_blktoobig
335544388L
isc_bufexh
335544389L
buffer exhausted
isc_syntaxerr
335544390L
isc_bufinuse
335544391L
buffer in use
isc_bdbincon
335544392L
internal error
5-23
5-24
Error code
Number
Message
isc_reqinuse
335544393L
request in use
isc_badodsver
335544394L
isc_relnotdef
335544395L
isc_fldnotdef
335544396L
isc_dirtypage
335544397L
internal error
isc_waifortra
335544398L
internal error
isc_doubleloc
335544399L
internal error
isc_nodnotfnd
335544400L
internal error
isc_dupnodfnd
335544401L
internal error
isc_locnotmar
335544402L
internal error
isc_badpagtyp
335544403L
isc_corrupt
335544404L
database corrupted
isc_badpage
335544405L
isc_badindex
335544406L
index is broken
isc_dbbnotzer
335544407L
isc_tranotzer
335544408L
isc_trareqmis
335544409L
transactionrequest mismatch
(synchronization error)
isc_badhndcnt
335544410L
isc_wrotpbver
335544411L
isc_wroblrver
335544412L
isc_wrodpbver
335544413L
isc_blobnotsup
335544414L
isc_badrelation
335544415L
database corrupted
isc_nodetach
335544416L
internal error
Language Reference
Number
Message
isc_notremote
335544417L
internal error
isc_trainlim
335544418L
transaction in limbo
isc_notinlim
335544419L
isc_traoutsta
335544420L
transaction outstanding
isc_connect_reject
335544421L
isc_dbfile
335544422L
internal error
isc_orphan
335544423L
internal error
isc_no_lock_mgr
335544424L
isc_ctxinuse
335544425L
isc_ctxnotdef
335544426L
isc_datnotsup
335544427L
isc_badmsgnum
335544428L
isc_badparnum
335544429L
isc_virmemexh
335544430L
isc_blocking_signal
335544431L
isc_lockmanerr
335544432L
isc_journerr
335544433L
isc_keytoobig
335544434L
isc_nullsegkey
335544435L
isc_sqlerr
335544436L
isc_wrodynver
335544437L
isc_funnotdef
335544438L
isc_funmismat
335544439L
isc_bad_msg_vec
335544440L
isc_bad_detach
335544441L
isc_noargacc_read
335544442L
5-25
5-26
Error code
Number
Message
isc_noargacc_write
335544443L
isc_read_only
335544444L
isc_ext_err
335544445L
isc_non_updatable
335544446L
not updatable
isc_no_rollback
335544447L
no rollback performed
isc_bad_sec_info
335544448L
isc_invalid_sec_info
335544449L
isc_misc_interpreted
335544450L
<string>
isc_update_conflict
335544451L
isc_unlicensed
335544452L
isc_obj_in_use
335544453L
isc_nofilter
335544454L
isc_shadow_accessed
335544455L
isc_invalid_sdl
335544456L
isc_out_of_bounds
335544457L
isc_invalid_dimension
335544458L
isc_rec_in_limbo
335544459L
isc_shadow_missing
335544460L
isc_cant_validate
335544461L
isc_cant_start_journal
335544462L
isc_gennotdef
335544463L
isc_cant_start_logging
335544464L
isc_bad_segstr_type
335544465L
Language Reference
Number
Message
isc_foreign_key
335544466L
isc_high_minor
335544467L
isc_tra_state
335544468L
isc_trans_invalid
335544469L
isc_buf_invalid
335544470L
isc_indexnotdefined
335544471L
isc_login
335544472L
isc_invalid_bookmark
335544473L
isc_bad_lock_level
335544474L
isc_relation_lock
335544475L
isc_record_lock
335544476L
isc_max_idx
335544477L
isc_jrn_enable
335544478L
isc_old_failure
335544479L
isc_old_in_progress
335544480L
isc_old_no_space
335544481L
isc_num_old_files
335544483L
isc_bad_stmt_handle
335544485L
isc_stream_not_defined
335544502L
isc_shutinprog
335544506L
isc_range_in_use
335544507L
5-27
5-28
Error code
Number
Message
isc_range_not_found
335544508L
isc_charset_not_found
335544509L
isc_lock_timeout
335544510L
isc_prcnotdef
335544511L
isc_prcmismat
335544512L
isc_codnotdef
335544515L
isc_xcpnotdef
335544516L
isc_except
335544517L
exception <digit>
isc_cache_restart
335544518L
isc_bad_lock_handle
335544519L
isc_shutdown
335544528L
isc_existing_priv_mod
335544529L
isc_primary_key_ref
335544530L
isc_primary_key_notnull
335544531L
isc_ref_cnstrnt_notfound
335544532L
isc_foreign_key_notfound
335544533L
isc_ref_cnstrnt_update
335544534L
isc_check_cnstrnt_update
335544535L
isc_check_cnstrnt_del
335544536L
isc_integ_index_seg_del
335544537L
isc_integ_index_seg_mod
335544538L
isc_integ_index_del
335544539L
Language Reference
Number
Message
isc_integ_index_mod
335544540L
isc_check_trig_del
335544541L
isc_check_trig_update
335544542L
isc_cnstrnt_fld_del
335544543L
isc_cnstrnt_fld_rename
335544544L
isc_rel_cnstrnt_update
335544545L
isc_constaint_on_view
335544546L
isc_invld_cnstrnt_type
335544547L
isc_primary_key_exists
335544548L
isc_systrig_update
335544549L
isc_not_rel_owner
335544550L
isc_grant_obj_notfound
335544551L
isc_grant_fld_notfound
335544552L
isc_grant_nopriv
335544553L
isc_nonsql_security_rel
335544554L
isc_nonsql_security_fld
335544555L
isc_shutfail
335544557L
isc_check_constraint
335544558L
isc_bad_svc_handle
335544559L
isc_shutwarn
335544560L
5-29
Number
Message
isc_wrospbver
335544561L
isc_bad_spb_form
335544562L
isc_svcnotdef
335544563L
isc_no_jrn
335544564L
isc_transliteration_failed
335544565L
isc_text_subtype
335544568L
isc_dsql_error
335544569L
isc_dsql_command_err
335544570L
Invalid command
isc_dsql_constant_err
335544571L
isc_dsql_cursor_err
335544572L
Cursor unknown
isc_dsql_datatype_err
335544573L
Datatype unknown
isc_dsql_decl_err
335544574L
isc_dsql_cursor_update_err
335544575L
isc_dsql_cursor_open_err
335544576L
isc_dsql_cursor_close_err
335544577L
isc_dsql_field_err
335544578L
Column unknown
isc_dsql_internal_err
335544579L
Internal error
isc_dsql_relation_err
335544580L
Table unknown
isc_dsql_procedure_err
335544581L
Procedure unknown
isc_dsql_request_err
335544582L
Request unknown
isc_dsql_sqlda_err
335544583L
5-30
isc_dsql_var_count_err
335544584L
isc_dsql_stmt_handle
335544585L
isc_dsql_function_err
335544586L
Function unknown
isc_dsql_blob_err
335544587L
isc_collation_not_found
335544588L
Language Reference
Number
Message
isc_collation_not_for_charset
335544589L
isc_dsql_dup_option
335544590L
isc_dsql_tran_err
335544591L
isc_dsql_invalid_array
335544592L
isc_dsql_max_arr_dim_exce
eded
335544593L
isc_dsql_arr_range_error
335544594L
isc_dsql_trigger_err
335544595L
Trigger unknown
isc_dsql_subselect_err
335544596L
isc_dsql_crdb_prepare_err
335544597L
isc_specify_field_err
335544598L
isc_num_field_err
335544599L
isc_col_name_err
335544600L
isc_where_err
335544601L
isc_table_view_err
335544602L
isc_distinct_err
335544603L
isc_key_field_count_err
335544604L
isc_subquery_err
335544605L
isc_expression_eval_err
335544606L
isc_node_err
335544607L
isc_command_end_err
335544608L
isc_index_name
335544609L
INDEX <string>
5-31
5-32
Error code
Number
Message
isc_exception_name
335544610L
EXCEPTION <string>
isc_field_name
335544611L
COLUMN <string>
isc_token_err
335544612L
Token unknown
isc_union_err
335544613L
isc_dsql_construct_err
335544614L
isc_field_aggregate_err
335544615L
isc_field_ref_err
335544616L
isc_order_by_err
335544617L
isc_return_mode_err
335544618L
isc_extern_func_err
335544619L
isc_alias_conflict_err
335544620L
isc_procedure_conflict_error
335544621L
isc_relation_conflict_err
335544622L
isc_dsql_domain_err
335544623L
isc_idx_seg_err
335544624L
isc_node_name_err
335544625L
isc_table_name
335544626L
TABLE <string>
isc_proc_name
335544627L
PROCEDURE <string>
isc_idx_create_err
335544628L
isc_dependency
335544630L
isc_idx_key_err
335544631L
isc_dsql_file_length_err
335544632L
isc_dsql_shadow_number_er
r
335544633L
Language Reference
Number
Message
isc_dsql_token_unk_err
335544634L
isc_dsql_no_relation_alias
335544635L
isc_indexname
335544636L
isc_no_stream_plan
335544637L
isc_stream_twice
335544638L
isc_stream_not_found
335544639L
isc_collation_requires_text
335544640L
isc_dsql_domain_not_found
335544641L
isc_index_unused
335544642L
isc_dsql_self_join
335544643L
isc_stream_bof
335544644L
isc_stream_crack
335544645L
isc_db_or_file_exists
335544646L
isc_invalid_operator
335544647L
isc_conn_lost
335544648L
isc_bad_checksum
335544649L
bad checksum
isc_page_type_err
335544650L
isc_ext_readonly_err
335544651L
isc_sing_select_err
335544652L
isc_psw_attach
335544653L
isc_psw_start_trans
335544654L
isc_invalid_direction
335544655L
5-33
Number
Message
isc_dsql_var_conflict
335544656L
isc_dsql_no_blob_array
335544657L
Array/Blob/DATE /TIME/TIMESTAMP
datatypes not allowed in arithmetic
isc_dsql_base_table
335544658L
isc_duplicate_base_table
335544659L
isc_view_alias
335544660L
isc_index_root_page_full
335544661L
isc_dsql_blob_type_unknown
335544662L
isc_req_max_clones_exceed
ed
335544663L
isc_dsql_duplicate_spec
335544664L
isc_unique_key_violation
335544665L
isc_srvr_version_too_old
335544666L
5-34
isc_drdb_completed_with_err
s
335544667L
isc_dsql_procedure_use_err
335544668L
isc_dsql_count_mismatch
335544669L
isc_blob_idx_err
335544670L
isc_array_idx_err
335544671L
isc_key_field_err
335544672L
isc_no_delete
335544673L
cannot delete
isc_del_last_field
335544674L
Language Reference
Number
Message
isc_sort_err
335544675L
sort error
isc_sort_mem_err
335544676L
isc_version_err
335544677L
isc_inval_key_posn
335544678L
isc_no_segments_err
335544679L
isc_crrp_data_err
335544680L
isc_rec_size_err
335544681L
isc_dsql_field_ref
335544682L
isc_req_depth_exceeded
335544683L
isc_no_field_access
335544684L
isc_no_dbkey
335544685L
isc_dsql_open_cursor_reque
st
335544688L
isc_ib_error
335544689L
InterBase error
isc_cache_redef
335544690L
Cache redefined
isc_cache_too_small
335544691L
isc_precision_err
335544697L
isc_scale_nogt
335544698L
isc_expec_short
335544699L
isc_expec_long
335544700L
isc_expec_ushort
335544701L
isc_like_escape_invalid
335544702L
isc_svcnoexe
335544703L
isc_net_lookup_err
335544704L
isc_service_unknown
335544705L
isc_host_unknown
335544706L
Host unknown
5-35
5-36
Error code
Number
Message
isc_grant_nopriv_on_base
335544707L
isc_dyn_fld_ambiguous
335544708L
isc_dsql_agg_ref_err
335544709L
isc_complex_view
335544710L
isc_unprepared_stmt
335544711L
isc_expec_positive
335544712L
isc_dsql_sqlda_value_err
335544713L
isc_invalid_array_id
335544714L
invalid Blob id
isc_ext_file_uns_op
335544715L
isc_svc_in_use
335544716L
isc_err_stack_limit
335544717L
isc_invalid_key
335544718L
isc_net_init_error
335544719L
isc_loadlib_failure
335544720L
isc_network_error
335544721L
isc_net_connect_err
335544722L
isc_net_connect_listen_err
335544723L
isc_net_event_connect_err
335544724L
isc_net_event_listen_err
335544725L
isc_net_read_err
335544726L
isc_net_write_err
335544727L
isc_integ_index_deactivate
335544728L
Language Reference
Number
Message
isc_integ_deactivate_primary
335544729L
isc_unsupported_network_dri
ve
335544732L
isc_io_create_err
335544733L
isc_io_open_err
335544734L
isc_io_close_err
335544735L
isc_io_read_err
335544736L
isc_io_write_err
335544737L
isc_io_delete_err
335544738L
isc_io_access_err
335544739L
isc_udf_exception
335544740L
isc_lost_db_connection
335544741L
isc_no_write_user_priv
335544742L
isc_token_too_long
335544743L
isc_max_att_exceeded
335544744L
isc_login_same_as_role_na
me
335544745L
isc_reftable_requires_pk
335544746L
isc_usrname_too_long
335544747L
isc_password_too_long
335544748L
isc_usrname_required
335544749L
isc_password_required
335544750L
isc_bad_protocol
335544751L
5-37
5-38
Error code
Number
Message
isc_dup_usrname_found
335544752L
isc_usrname_not_found
335544753L
isc_error_adding_sec_record
335544754L
isc_error_modifying_sec_rec
ord
335544755L
isc_error_deleting_sec_recor
d
335544756L
eisc_rror_updating_sec_db
335544757L
isc_sort_rec_size_err
335544758L
isc_bad_default_value
335544759L
isc_invalid_clause
335544760L
isc_too_many_handles
335544761L
isc_optimizer_blk_exc
335544762L
Language Reference
Chapter
Chapter 6
This chapter describes the InterBase system tables and SQL system views.
Important
Only InterBase system object names can begin with the characters RDB$ or
TMP$. No other object name in InterBase can begin with these character
sequences, including tables, views, triggers, stored procedures, indexes,
generators, domains, and roles.
Overview
The InterBase system tables contain and track metadata. InterBase automatically
creates system tables when a database is created. Each time a user creates or
modifies metadata through data definition, the SQL data definition utility
automatically updates the system tables.
The temporary system tables allow access to information about the database and
its connections and a degree of control over transactions. By default, all users can
select from permanent system tables, but only the database owner and the
SYSDBA user can write to them. To gain access to temporary system tables,
explicit access has to be granted to them by the database owner or the SYSDBA.
These users can grant write access to others if they wish. See the Operations
Guide for details about system table security.
SQL system views provide information about existing integrity constraints for a
database. You must create system views yourself by creating and running an isql
script after database definition. See System Views on page 6-51 for the code
that creates them as well as the resulting table structures.
6-1
System Tables
System Tables
This table lists the InterBase system tables. The names of system tables and their
columns start with RDB$.
Table 6.1 System tables
RDB$CHARACTER_SETS
RDB$LOG_FILES
RDB$CHECK_CONSTRAINTS
RDB$PAGES
RDB$COLLATIONS
RDB$PROCEDURE_PARAMETERS
RDB$DATABASE
RDB$PROCEDURES
RDB$DEPENDENCIES
RDB$REF_CONSTRAINTS
RDB$EXCEPTIONS
RDB$RELATION_CONSTRAINTS
RDB$FIELD_DIMENSIONS
RDB$RELATION_FIELDS
RDB$FIELDS
RDB$RELATIONS
RDB$FILES
RDB$ROLES
RDB$FILTERS
RDB$SECURITY_CLASSES
RDB$FORMATS
RDB$TRANSACTIONS
RDB$FUNCTION_ARGUMENTS
RDB$TRIGGER_MESSAGES
RDB$FUNCTIONS
RDB$TRIGGERS
RDB$GENERATORS
RDB$TYPES
RDB$INDEX_SEGMENTS
RDB$USER_PRIVILEGES
RDB$INDICES
RDB$USERS
RDB$VIEW_RELATIONS
6-2
Language Reference
System Tables
RDB$CHARACTER_SETS
RDB$CHARACTER_SETS describes the valid character sets available in InterBase.
Datatype
Length
Description
RDB$CHARACTER_SET_NAME
CHAR
67
RDB$FORM_OF_USE
CHAR
67
RDB$NUMBER_OF_CHARACTERS
INTEGER
RDB$DEFAULT_COLLATE_NAME
CHAR
RDB$CHARACTER_SET_ID
SMALLINT
RDB$SYSTEM_FLAG
SMALLINT
RDB$DESCRIPTION
BLOB
RDB$FUNCTION_NAME
CHAR
RDB$BYTES_PER_CHARACTER
SMALLINT
Number of characters in a
particular character set; for
example, the set of Japanese
characters
67
67
6-3
System Tables
RDB$CHECK_CONSTRAINTS
RDB$CHECK_CONSTRAINTS stores database integrity constraint information for
CHECK constraints. In addition, the table stores information for constraints
implemented with NOT NULL.
Datatype
Length Description
RDB$CONSTRAINT_NAME
CHAR
67
RDB$TRIGGER_NAME
CHAR
67
RDB$COLLATIONS
RDB$COLLATIONS records the valid collating sequences available for use in
InterBase.
Table 6.4 RDB$COLLATIONS
6-4
Column name
Datatype
Length
Description
RDB$COLLATION_NAME
CHAR
67
RDB$COLLATION_ID
SMALLINT
RDB$CHARACTER_SET_ID
SMALLINT
RDB$COLLATION_ATTRIBUTES
SMALLINT
Language Reference
System Tables
Datatype
Length
RDB$SYSTEM_FLAG
SMALLINT
RDB$DESCRIPTION
BLOB
RDB$FUNCTION_NAME
CHAR
67
Description
RDB$DATABASE
RDB$DATABASE defines a database.
Datatype
Length Description
RDB$DESCRIPTION
BLOB
RDB$RELATION_ID
SMALLINT
RDB$SECURITY_CLASS
CHAR
67
CHAR
RDB$PAGE_CACHE
INTEGER
RDB$PROCEDURE_CACHE
INTEGER
RDB$TRIGGER_CACHE
INTEGER
RDB$RELATION_CACHE
SMALLINT
67
6-5
System Tables
Datatype
Length Description
RDB$FLUSH_INTERVAL
INTEGER
RDB$LINGER_INTERVAL
INTEGER
RDB$RECLAIM_INTERVAL
INTEGER
RDB$SWEEP_INTERVAL
INTEGER
RDB$GROUP_COMMIT
CHAR(1)
RDB$PASSWORD_DIGEST
VARCHAR(
16)
RDB$DEPENDENCIES
RDB$DEPENDENCIES keeps track of the tables and columns upon which other
system objects depend. These objects include views, triggers, and computed
columns. InterBase uses this table to ensure that a column or table cannot be
deleted if it is used by any other object.
Table 6.6 RDB$DEPENDENCIES
Column name
Datatype
Length
Description
RDB$DEPENDENT_NAME
CHAR
67
RDB$DEPENDED_ON_NAME CHAR
67
RDB$FIELD_NAME
67
6-6
CHAR
Language Reference
System Tables
Datatype
RDB$DEPENDENT_TYPE
SMALLINT
Length
Description
Describes the object type of the object
referenced in the
RDB$DEPENDENT_NAME column; type
codes (RDB$TYPES):
0 - table
1 - view
2 - trigger
3 - computed_field
4 - validation
5 - procedure
7 - exception
8 - user
9 - field
10 - index
0 - table
1 - view
2 - trigger
3 - computed_field
4 - validation
5 - procedure
7 - exception
8 - user
9 - field
10 - index
11 - generator
14 - External
Functions
15 - Encryption
RDB$ENCRYPTIONS
RDB$ENCRYPTIONS describes the characteristics of encryptions
stored in the database.
6-7
System Tables
6-8
Column name
Datatype
Length Description
RDB$ENCRYPTION_NAME
CHAR
67
RDB$ENCRYPTION_TYPE
CHAR
16
RDB$ENCRYPTION_CIPHE
R
CHAR
16
RDB$ENCRYPTION_
LENGTH
SMALLINT
RDB$ENCRYPTION_INIT_
VECTOR
CHAR
RDB$ENCRYPTION_PAD
CHAR
RDB$ENCRYPTION_VALUE
CHAR
68
RDB$ENCRYPTION_SALT
CHAR
68
RDB$ENCRYPTION_
TIMESTAMP
TIMESTA
MP
Language Reference
System Tables
Datatype
Length Description
RDB$SECURITY_CLASS
CHAR
67
RDB$OWNER_NAME
CHAR
67
RDB$PASSWORD2
VARCHA
R
68
RDB$SYSTEM_FLAG
SMALLIN
T
0: User-defined 1: Systemdefined.
RDB$FLAGS
SMALLIN
T
RDB$DESCRIPTION
BLOB
RDB$EXCEPTIONS
RDB$EXCEPTIONS describes error conditions related to stored procedures,
Datatype
Length
Description
RDB$EXCEPTION_NAME
CHAR
67
RDB$EXCEPTION_NUMBER
INTEGER
RDB$MESSAGE
VARCHAR
RDB$DESCRIPTION
BLOB
RDB$SYSTEM_FLAG
SMALLINT
Displays null
RDB$FIELD_DIMENSIONS
RDB$FIELD_DIMENSIONS describes each dimension of an array column.
6-9
System Tables
Datatype
Length
Description
RDB$FIELD_NAME
CHAR
67
RDB$DIMENSION
SMALLINT
RDB$LOWER_BOUND
INTEGER
RDB$UPPER_BOUND
INTEGER
RDB$FIELDS
RDB$FIELDS defines the characteristics of a column. Each domain or column has a
corresponding row in RDB$FIELDS. Columns are added to tables by means of an
entry in the RDB$RELATION_FIELDS table, which describes local characteristics.
For domains, RDB$FIELDS includes domain name, null status, and default values.
SQL columns are defined in RDB$RELATION_FIELDS. For both domains and simple
columns, RDB_RELATION_FIELDS can contain default and null status information.
Table 6.10 RDB$FIELDS
6-10
Column name
Datatype
Length
RDB$FIELD_NAME
CHAR
67
RDB$QUERY_NAME
CHAR
67
RDB$VALIDATION_BLR
BLOB
RDB$VALIDATION_SOURCE
BLOB
RDB$COMPUTED_BLR
BLOB
RDB$COMPUTED_SOURCE
BLOB
Language Reference
Description
System Tables
Datatype
Length
Description
RDB$DEFAULT_VALUE
BLOB
RDB$DEFAULT_SOURCE
BLOB
RDB$FIELD_LENGTH
SMALLINT
D_FLOAT - 8
DOUBLE - 8
DATE - 4
BLOB - 8
TIME - 4
INT64 - 8
SHORT - 2
LONG - 4
QUAD - 8
FLOAT - 4
TIMESTAMP - 8
BOOLEAN - 2
RDB$FIELD_PRECISION
SMALLINT
RDB$FIELD_SCALE
SMALLINT
6-11
System Tables
Datatype
RDB$FIELD_TYPE
SMALLINT
Length
Description
Specifies the datatype of the column
being defined; changing the value of
this column automatically changes the
datatype for all columns based on the
column being defined
Valid values are:
BOOLEAN - 17
CHAR - 14
CSTRING - 40
D_FLOAT - 11
DOUBLE - 27
FLOAT - 10
INT64 - 16
BLOB - 261
INTEGER - 8
BLOB_ID - 45
QUAD - 9
SMALLINT - 7
DATE - 12
(dialect 3 DATE)
TIME - 13
TIMESTAMP - 35
VARCHAR - 37
Restrictions:
The value of this column cannot be
changed to or from BLOB
Non-numeric data causes a
conversion error in a column
changed from CHAR to numeric
Changing data from CHAR to numeric
and back again adversely affects index
performance; for best results, delete
and re-create indexes when making
this type of change
6-12
Language Reference
System Tables
Datatype
RDB$FIELD_SUB_TYPE
SMALLINT
Length
Description
Used to distinguish types of Blobs,
CHARs, and integers
1 If RDB$FIELD_TYPE is 261 (Blob),
predefined subtypes can be:
0 - unspecified
1 - text
2 - BLR (Binary
Language
Representation
)
3 - access
control list
4 - reserved for
future use
5 - encoded
description of a
tables current
metadata
6 - description of
multi-database
transaction that
finished irregularly
2 If RDB$FIELD_TYPE is 14 (CHAR),
columns can be:
0 - type is unspecified
1 - fixed BINARY data
Corresponds to the
RDB$FIELD_SUB_TYPE column in the
RDB$COLLATIONS table
3 If RDB$FIELD_TYPE is 7
(SMALLINT), 8 (INTEGER), or
16 (INT64), the original declaration
was:
0 or NULL - RDB$FIELD_TYPE
1 - NUMERIC
2 - DECIMAL
RDB$MISSING_VALUE
BLOB
RDB$MISSING_SOURCE
BLOB
RDB$DESCRIPTION
BLOB
RDB$SYSTEM_FLAG
SMALLINT
RDB$QUERY_HEADER
BLOB
RDB$SEGMENT_LENGTH
SMALLINT
Used for Blob columns only; a nonbinding suggestion for the length of
Blob buffers
RDB$EDIT_STRING
VARCHAR
125
6-13
System Tables
Datatype
Length
Description
RDB$EXTERNAL_LENGTH
SMALLINT
RDB$EXTERNAL_SCALE
SMALLINT
RDB$EXTERNAL_TYPE
SMALLINT
6-14
BOOLEAN - 17
CHAR - 14
CSTRING - 40
D_FLOAT - 11
DOUBLE - 27
FLOAT - 10
BLOB - 261
INTEGER - 8
BLOB_ID - 45
QUAD - 9
SMALLINT - 7
DATE - 12
(dialect 3 DATE)
TIME - 13
TIMESTAMP - 35
VARCHAR - 37
INT64 - 16
RDB$DIMENSIONS
SMALLINT
RDB$NULL_FLAG
SMALLINT
RDB$CHARACTER_LENGTH
SMALLINT
RDB$COLLATION_ID
SMALLINT
Language Reference
System Tables
Datatype
RDB$CHARACTER_SET_ID
SMALLINT
RDB$ENCRYPTION_ID
SMALLIN
T
RDB$DECRYPT_
DEFAULT_ VAULES
BLOB
BLOB
RDB$DECRYPT_DEFAULT_
SOURCE
Length
Description
ID indicating character set for the
character or Blob columns; joins to the
CHARACTER_SET_ID column of the
RDB$CHARACTER_SETS system table
RDB$FILES
RDB$FILES lists the secondary files and shadow files for a database.
Datatype
Length
Description
RDB$FILE_NAME
VARCHAR
253
RDB$FILE_SEQUENCE
SMALLINT
RDB$FILE_START
INTEGER
RDB$FILE_LENGTH
INTEGER
RDB$FILE_FLAGS
SMALLINT
RDB$SHADOW_NUMBER
SMALLINT
6-15
System Tables
RDB$FILTERS
RDB$FILTERS tracks information about a Blob filter.
Datatype
Length
Description
RDB$FUNCTION_NAME
CHAR
67
RDB$DESCRIPTION
BLOB
RDB$MODULE_NAME
VARCHAR
253
RDB$ENTRYPOINT
CHAR
31
RDB$INPUT_SUB_TYPE
SMALLINT
RDB$OUTPUT_SUB_TYP
E
SMALLINT
RDB$SYSTEM_FLAG
SMALLINT
RDB$FORMATS
RDB$FORMATS keeps track of the format versions of the columns in a table.
InterBase assigns the table a new format number at each change to a column
definition. Direct metadata operations such as ALTER TABLE increment the format
version; so do creating, dropping, activating, and deactivating triggers. This table
allows existing application programs to access a changed table, without needing to
be recompiled.
Note
6-16
InterBase allows only 255 changes to a tables metadata. Once the limit is reached,
the database must be backed up and restored before more metadata changes can
be made. Only changes that affect a rows structure count toward this limit.
Changing a trigger from active to inactive, for example, does not count toward the
limit.
Language Reference
System Tables
Datatype
Length Description
RDB$RELATION_ID
SMALLINT
RDB$FORMAT
SMALLINT
RDB$DESCRIPTOR
BLOB
RDB$FUNCTION_ARGUMENTS
RDB$FUNCTION_ARGUMENTS defines the attributes of a function argument.
Datatype
Length
RDB$FUNCTION_NAME
CHAR
67
Description
Unique name of the function with which
the argument is associated; must
correspond to a function name in
RDB$FUNCTIONS
RDB$ARGUMENT_POSITIO
N
SMALLINT
RDB$MECHANISM
SMALLINT
RDB$FIELD_TYPE
SMALLINT
BLOB - 261
BLOB_ID - 45
BOOLEAN - 17
CHAR - 14
CSTRING - 40
D_FLOAT - 11
DOUBLE - 27
FLOAT - 10
INTEGER - 8
QUAD - 9
SMALLINT - 7
DATE - 12
(dialect 3 DATE)
TIME - 13
TIMESTAMP - 35
VARCHAR - 37
INT64 - 16
6-17
System Tables
Datatype
Length
Description
RDB$FIELD_SCALE
SMALLINT
RDB$FIELD_LENGTH
SMALLINT
BLOB - 8
BOOLEAN - 2
D_FLOAT - 8
DATE - 4
DOUBLE - 8
FLOAT - 4
INT64 - 8
LONG - 4
QUAD - 8
SHORT - 2
TIME - 4
TIMESTAMP - 8
RDB$FIELD_SUB_TYPE
SMALLINT
If RDB$FIELD_TYPE is 7 (SMALLINT),
8 (INTEGER), or 16 (INT64) the
subtype can be:
0 or NULL - RDB$FIELD_TYPE
1 - NUMERIC
2 - DECIMAL
RDB$CHARACTER_SET_ID
SMALLINT
RDB$FIELD_PRECISION
SMALLINT
RDB$FUNCTIONS
RDB$FUNCTIONS defines a user-defined function.
6-18
Column name
Datatype
Length
Description
RDB$FUNCTION_NAME
CHAR
67
RDB$FUNCTION_TYPE
SMALLINT
RDB$QUERY_NAME
CHAR
RDB$DESCRIPTION
BLOB
Language Reference
System Tables
Datatype
Length
Description
RDB$MODULE_NAME
VARCHAR
253
RDB$ENTRYPOINT
CHAR
31
RDB$RETURN_ARGUMENT
SMALLINT
RDB$SYSTEM_FLAG
SMALLINT
RDB$GENERATORS
RDB$GENERATORS stores information about generators, which provide the ability to
generate a unique identifier for a table.
Datatype
Length
Description
RDB$GENERATOR_NAME
CHAR
67
RDB$GENERATOR_ID
SMALLINT
RDB$SYSTEM_FLAG
SMALLINT
6-19
System Tables
RDB$INDEX_SEGMENTS
RDB$INDEX_SEGMENTS specifies the columns that comprise an index for a table.
Modifying these rows corrupts rather than changes an index unless the
RDB$INDICES row is deleted and re-created in the same transaction.
Datatype
Length
Description
RDB$INDEX_NAME
CHAR
67
RDB$FIELD_NAME
CHAR
67
RDB$FIELD_POSITION
SMALLINT
RDB$INDICES
RDB$INDICES defines the index structures that allow InterBase to locate rows in the
database more quickly. Because InterBase provides both simple indexes (a singlekey column) and multi-segment indexes (multiple-key columns), each index
defined in this table must have corresponding occurrences in the
RDB$INDEX_SEGMENTS table.
6-20
Column name
Datatype
Length Description
RDB$INDEX_NAME
CHAR
67
RDB$RELATION_NAME
CHAR
67
RDB$INDEX_ID
SMALLINT
Language Reference
System Tables
Datatype
Length Description
RDB$UNIQUE_FLAG
SMALLINT
RDB$DESCRIPTION
BLOB
RDB$SEGMENT_COUNT
SMALLINT
RDB$INDEX_INACTIVE
SMALLINT
RDB$INDEX_TYPE
SMALLINT
RDB$FOREIGN_KEY
CHAR
RDB$SYSTEM_FLAG
SMALLINT
RDB$EXPRESSION_BLR
BLOB
RDB$EXPRESSION_SOURC
E
BLOB
RDB$STATISTICS
DOUBLE
PRECISION
31
6-21
System Tables
RDB$JOURNAL_ARCHIVES
RDB$JOURNAL_ARCHIVES stores information about the repository of database
and journal archive files.
Table 6.19 RDB$JOURNAL_ARCHIVES
Column name
Datatype
Length
Description
RDB$ARCHIVE_
NAME
VARCHAR
1024
RDB$ARCHIVE_
TYPE
CHAR
RDB$ARCHIVE_
LENGTH
INT64
RDB$ARCHIVE_
SEQUENCE
INTEGER
RDB$ARCHIVE_
TIMESTAMP
TIMESTAMP
RDB$DEPENDED_
ON_SEQUENCE
INTEGER
RDB$DEPENDED_
ON_TIMESTAMP
TIMESTAMP
RDB$LOG_FILES
RDB$LOG_FILES is no longer used.
RDB$PAGES
RDB$PAGES keeps track of each page allocated to the database.
Important
6-22
Language Reference
System Tables
RDB$PROCEDURE_PARAMETERS
Table 6.20 RDB$PAGES
Column name
Datatype
Length Description
RDB$PAGE_NUMBER
INTEGER
RDB$RELATION_ID
SMALLINT
RDB$PAGE_SEQUENC
E
INTEGER
RDB$PAGE_TYPE
SMALLINT
of a databases procedures.
Table 6.21 RDB$PROCEDURE_PARAMETERS
Column name
Datatype
Length Description
RDB$PARAMETER_NAME
CHAR
67
Parameter name
RDB$PROCEDURE_NAME
CHAR
67
RDB$PARAMETER_NUMBER
SMALLINT
RDB$PARAMETER_TYPE
SMALLINT
Parameter datatype
Values are:
0 = input
1 = output
RDB$FIELD_SOURCE
CHAR
RDB$DESCRIPTION
BLOB
RDB$SYSTEM_FLAG
SMALLINT
31
RDB$PROCEDURES
RDB$PROCEDURES stores information about a databases stored procedures.
6-23
System Tables
6-24
Column name
Datatype
Length
Description
RDB$PROCEDURE_NAME
CHAR
67
Procedure name
RDB$PROCEDURE_ID
SMALLINT
Procedure number
RDB$PROCEDURE_INPUTS
SMALLINT
PROCEDURE_OUTPUTS
SMALLINT
RDB$DESCRIPTION
BLOB
RDB$PROCEDURE_SOURC
E
BLOB
RDB$PROCEDURE_BLR
BLOB
RDB$SECURITY_CLASS
CHAR
67
RDB$OWNER_NAME
CHAR
67
RDB$RUNTIME
BLOB
RDB$SYSTEM_FLAG
SMALLINT
Language Reference
System Tables
RDB$REF_CONSTRAINTS
RDB$REF_CONSTRAINTS stores referential integrity constraint information.
Datatype
Length
Description
RDB$3CONSTRAINT_NAM
E
CHAR
67
RDB$CONST_NAME_UQ
CHAR
67
RDB$MATCH_OPTION
CHAR
RDB$UPDATE_RULE
CHAR
11
RDB$DELETE_RULE
CHAR
11
RDB$RELATION_CONSTRAINTS
RDB$RELATION_CONSTRAINTS stores information about integrity constraints for
tables.
Table 6.24 RDB$RELATION_CONSTRAINTS
Column name
Datatype
Length
Description
RDB$CONSTRAINT_NAME
CHAR
67
RDB$CONSTRAINT_TYPE
CHAR
11
RDB$RELATION_NAME
CHAR
67
6-25
System Tables
Datatype
Length
Description
RDB$DEFERRABLE
CHAR
RDB$INITIALLY_DEFERRED
CHAR
RDB$INDEX_NAME
CHAR
67
RDB$RELATION_FIELDS
For database tables, RDB$RELATION_FIELDS lists columns and describes column
characteristics for domains.
SQL columns are defined in RDB$RELATION_FIELDS. The column name is
correlated in the RDB$FIELD_SOURCE column to an underlying entry in RDB$FIELDS
that contains a system name (SQL$<n>). This entry includes information such as
column type and length. For both domains and simple columns, this table may
contain default and nullability information.
Table 6.25 RDB$RELATION_FIELDS
6-26
Column name
Datatype
Length
Description
RDB$QUERY_NAME
CHAR
31
RDB$BASE_FIELD
CHAR
31
RDB$EDIT_STRING
VARCHAR
125
Language Reference
System Tables
Datatype
Length
RDB$FIELD_POSITION
SMALLINT
RDB$QUERY_HEADER
BLOB
RDB$UPDATE_FLAG
SMALLINT
RDB$FIELD_ID
SMALLINT
RDB$VIEW_CONTEXT
SMALLINT
RDB$DESCRIPTION
BLOB
RDB$DEFAULT_VALUE
BLOB
RDB$SYSTEM_FLAG
SMALLINT
RDB$SECURITY_CLASS
CHAR
67
Description
CHAR
67
6-27
System Tables
Datatype
Length
Description
RDB$NULL_FLAG
SMALLINT
RDB$DEFAULT_SOURC
E
BLOB
RDB$COLLATION_ID
SMALLINT
RDB$DECRYPT_DEFAUL
T_ SOURCE
BLOB
RDB$DECRYPT_DEFAUL
T_ VALUE
BLOB
RDB$ENCRYPTION_ID
SMALLINT
RDB$RELATIONS
RDB$RELATIONS defines some of the characteristics of tables and views. Other
characteristics, such as the columns included in the table and a description of
each column, are stored in the RDB$RELATION_FIELDS table.
6-28
Column name
Datatype
RDB$VIEW_BLR
BLOB
RDB$VIEW_SOURCE
BLOB
RDB$_DESCRIPTION
BLOB
RDB$RELATION_ID
SMALLINT
Language Reference
Length
Description
System Tables
Datatype
Length
Description
RDB$SYSTEM_FLAG
SMALLINT
RDB$DBKEY_LENGTH
SMALLINT
RDB$FORMAT
SMALLINT
RDB$FIELD_ID
SMALLINT
RDB$RELATION_NAME
CHAR
67
RDB$SECURITY_CLASS
CHAR
67
RDB$EXTERNAL_FILE
VARCHAR
253
RDB$RUNTIME
BLOB
RDB$EXTERNAL_DESCRIPTI
ON
BLOB
Subtype
EXTERNAL_FILE_DESCRIPTION;
6-29
System Tables
Datatype
Length
Description
RDB$OWNER_NAME
CHAR
67
RDB$DEFAULT_CLASS
CHAR
31
RDB$FLAGS
SMALLINT
1 = SQL-defined table
2 = Global temporary table
4 = <reserved for future use>
8 = Delete temporary rows on
commit
16 = Preserve temporary rows on
commit; rows are deleted on
database detach
RDB$DATA_BLOCKING_FACT
OR
SMALLINT
RDB$BLOB_BLOCKING_FACT
OR
BLOB
RDB$ROLES
RDB$ROLES lists roles that have been defined in the database and the owner of
each role.
6-30
Language Reference
System Tables
Datatype
Length
Description
RDB$ROLE_NAME
CHAR
67
RDB$OWNER_NAME
CHAR
67
RDB$SECURITY_CLASSES
RDB$SECURITY_CLASSES defines access control lists and associates them with
databases, tables, views, and columns in tables and views. For all SQL objects,
the information in this table is duplicated in the RDB$USER_PRIVILEGES system
table.
Table 6.28 RDB$SECURITY_CLASSES
Column name
Datatype
Length
Description
RDB$SECURITY_CLAS
S
CHAR
67
RDB$ACL
BLOB
RDB$DESCRIPTION
BLOB
6-31
System Tables
RDB$TRANSACTIONS
RDB$TRANSACTIONS keeps track of all multi-database transactions.
Datatype
Length
Description
RDB$TRANSACTION_ID
INTEGER
RDB$TRANSACTION_STATE
SMALLINT
RDB$TIMESTAMP
DATE
RDB$TRANSACTION_DESCRIPTI
ON
BLOB
Subtype
TRANSACTION_DESCRIPTION;
RDB$TRIGGER_MESSAGES
RDB$TRIGGER_MESSAGES defines a trigger message and associates the message
6-32
Column name
Datatype
Length Description
RDB$TRIGGER_NAME
CHAR
67
RDB$MESSAGE_NUMBE
R
SMALLINT
RDB$MESSAGE
VARCHAR
Language Reference
78
System Tables
RDB$TRIGGERS
RDB$TRIGGERS defines triggers.
Datatype
Length Description
RDB$TRIGGER_NAME
CHAR
67
RDB$RELATION_NAME
CHAR
67
RDB$TRIGGER_SEQUENC
E
SMALLINT
RDB$TRIGGER_TYPE
SMALLINT
RDB$TRIGGER_SOURCE
BLOB
RDB$TRIGGER_BLR
BLOB
RDB$DESCRIPTION
BLOB
6-33
System Tables
Datatype
Length Description
RDB$TRIGGER_INACTIVE
SMALLINT
RDB$SYSTEM_FLAG
SMALLINT
RDB$FLAGS
SMALLINT
1 = SQL-defined trigger
2 = ignore permission checking
User-defined triggers require that the
user executing them have underlying
access permission to the objects
accessed by the trigger. However,
internal, system-defined triggers
occasionally need to bypass those
permission checks to enforce
database integrity.
RDB$TYPES
RDB$TYPES records enumerated datatypes and alias names for InterBase
character sets and collation orders. This capability is not available in the current
release.
Datatype
Length
Description
RDB$FIELD_NAME
CHAR
67
RDB$TYPE
SMALLINT
3 - computed_field
4 - validation
5 - procedure
6-34
Language Reference
System Tables
Datatype
Length
Description
RDB$TYPE_NAME
CHAR
67
RDB$DESCRIPTION
BLOB
RDB$SYSTEM_FLA
G
SMALLINT
RDB$USER_PRIVILEGES
RDB$USER_PRIVILEGES keeps track of the privileges assigned to a user through a
SQL GRANT statement. There is one occurrence of this table for each user/
privilege intersection.
Datatype
Length
Description
RDB$USER
CHAR
31
RDB$GRANTOR
CHAR
31
RDB$PRIVILEGE
CHAR
RDB$GRANT_OPTION
SMALLINT
RDB$RELATION_NAME
CHAR
ALL (A)
SELECT (S)
DELETE (D)
INSERT (I)
UPDATE (U)
REFERENCE (R)
MEMBER OF (for roles) (M)
DECRYPT (T)
ENCRYPT (E)
6-35
System Tables
Datatype
Length
Description
RDB$FIELD_NAME
CHAR
67
RDB$USER_TYPE
SMALLINT
RDB$OBJECT_TYPE
SMALLINT
RDB$USERS
RDB$USERS only permits users in that system table access to the database.
6-36
Column name
Datatype
Length
RDB$USER_NAME
(RDB$USER_NAME)
VARCHAR(128)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$SYSTEM_USER_NA
ME (RDB$USER_NAME)
VARCHAR(128)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$GROUP_NAME
(RDB$USER_NAME)
VARCHAR(128)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$UID (RDB$UID)
INTEGER
Nullable
RDB$GID (RDB$GID)
INTEGER
Nullable
RDB$PASSWORD
(RDB$PASSWORD)
VARCHAR(32)
CHARACTER SET
OCTETS Nullable
RDB$USER_ACTIVE
(RDB$USER_ACTIVE)
CHAR(2)
Nullable
RDB$USER_PRIVILEGE
(RDB$USER_PRIVILEGE)
INTEGER
Nullable
RDB$DESCRIPTION
(RDB$DESCRIPTION)
BLOB
RDB$FIRST_NAME
(RDB$NAME_PART)
VARCHAR(32)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$MIDDLE_NAME
(RDB$NAME_PART)
VARCHAR(32)
CHARACTER SET
UNICODE_FSS
Nullable
Language Reference
Description
System Tables
Datatype
Length
RDB$LAST_NAME
(RDB$NAME_PART
VARCHAR(32)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$DEFAULT_ROLE
(RDB$USER)
CHAR(67)
CHARACTER SET
UNICODE_FSS
Nullable
RDB$PASSWORD_DIGEST
(RDB$PASSWORD_DIGES
T)
VARCHAR(16)
Nullable
Description
RDB$VIEW_RELATIONS
RDB$VIEW_RELATIONS is not used by SQL objects.
Datatype
Length
Description
RDB$VIEW_NAME
CHAR
67
RDB$RELATION_NAME
CHAR
67
RDB$VIEW_CONTEXT
SMALLINT
RDB$CONTEXT_NAME
CHAR
6-37
TMP$DATABASE
TMP$POOL_BLOCKS
TMP$POOLS
TMP$PROCEDURES
TMP$RELATIONS
TMP$STATEMENTS
TMP$TRANSACTIONS
TMP$ATTACHMENTS
The TMP$ATTACHMENTS table contains one row for each connection to a database.
Table 6.36 TMP$ATTACHMENTS
6-38
Column name
Data type
Description
TMP$ATTACHMENT_ID
INTEGER
Connection identifier
TMP$DATABASE_ID
INTEGER
Database identifier
TMP$POOL_ID
INTEGER
Reserved
TMP$POOL_MEMORY
INTEGER
Reserved
TMP$STATEMENTS
SMALLINT
TMP$TRANSACTIONS
SMALLINT
TMP$TIMESTAMP
TIMESTAMP
TMP$QUANTUM
INTEGER
Units of execution
TMP$USER
CHAR[67]
User name
TMP$USER_IP_ADDR
CHAR [31]
User IP address
TMP$USER_HOST
CHAR [31]
TMP$USER_PROCESS
CHAR [31]
User process ID
TMP$STATE
CHAR [31]
CONNECTED, ACTIVE
TMP$PRIORITY
CHAR [31]
Reserved
TMP$DBKEY_ID
INTEGER
Transaction ID of dbkey
Language Reference
Data type
Description
TMP$ACTIVE_SORTS
SMALLINT
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGE
S
INTEGER
TMP$RECORD_BACKOUT
S
INTEGER
TMP$DATABASE
TMP$DATABASE contains one row for each database you are attached to.
Data type
Description
TMP$DATABASE_ID
INTEGER
Database identifier
TMP$DATABASE_PATH
VARCHAR[253]
Database pathname
TMP$ATTACHMENTS
SMALLINT
Number of active
connections
TMP$STATEMENTS
SMALLINT
Number of compiled
statements
TMP$STATE
CHAR[31]
TMP$ALLOCATED_PAGES
INTEGER
TMP$POOLS
INTEGER
6-39
6-40
Column name
Data type
Description
TMP$PROCEDURES
SMALLINT
Number of procedures
loaded
TMP$RELATIONS
SMALLINT
TMP$TRIGGERS
SMALLINT
TMP$ACTIVE_THREADS
SMALLINT
TMP$SORT_MEMORY
INTEGER
TMP$CURRENT_MEMORY
INTEGER
TMP$MAXIMUM_MEMORY
INTEGER
TMP$PERMANENT_POOL_MEMORY
INTEGER
TMP$CACHE_POOL_MEMORY
INTEGER
TMP$TRANSACTIONS
SMALLINT
Number of active
transactions
TMP$TRANSACTION_COMMITS
INTEGER
Number of transaction
commits
TMP$TRANSACTION_ROLLBACKS
INTEGER
Number of transaction
rollbacks
TMP$TRANSACTION_PREPARES
INTEGER
Number of transaction
prepares
TMP$TRANSACTION_DEADLOCKS
INTEGER
Number of transaction
deadlocks
TMP$TRANSACTION_CONFLICTS
INTEGER
Number of transaction
update conflicts
TMP$TRANSACTION_WAITS
INTEGER
TMP$NEXT_TRANSACTION
INTEGER
TMP$OLDEST_INTERESTING
INTEGER
TMP$OLDEST_ACTIVE
INTEGER
TMP$OLDEST_SNAPSHOT
INTEGER
TMP$CACHE_BUFFERS
INTEGER
Language Reference
Data type
Description
TMP$CACHE_PRECEDENCE
INTEGER
TMP$CACHE_LATCH_WAITS
INTEGER
TMP$CACHE_FREE_WAITS
INTEGER
TMP$CACHE_FREE_WRITES
INTEGER
TMP$SWEEP_INTERVAL
INTEGER
TMP$SWEEP_ACTIVE
CHAR[1]
Y (active) N (not-active)
TMP$SWEEP_RELATION
CHAR[67]
TMP$SWEEP_RECORDS
INTEGER
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
Records updated to
database
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGES
INTEGER
TMP$RECORD_BACKOUTS
INTEGER
6-41
TMP$HEAPS
TMP$HEAPS contains one row for each entry in the InterBase Random and Block
heap.
Data type
Description
TMP$HEAP_TYPE
CHAR[31]
RANDOM or BLOCK
TMP$HEX_ADDRESS
CHAR[31]
TMP$ADDRESS
NUMERIC(18,0)
TMP$FREE_MEMORY
INTEGER
TMP$POOL_BLOCKS
The TMP$POOL_BLOCKS table contains one row for each block of memory in each
pool.
Table 6.39 TMP$POOL_BLOCKS
6-42
Column name
Data
type
TMP$POOL_ID
INTEGER
TMP$ACC
INTEGER
TMP$ARR
INTEGER
TMP$ATT
INTEGER
TMP$BCB
INTEGER
TMP$BDB
INTEGER
TMP$BLB
INTEGER
Blob block
TMP$BLF
INTEGER
TMP$BMS
INTEGER
TMP$BTB
INTEGER
TMP$BTC
INTEGER
TMP$CHARSET
INTEGER
TMP$CSB
INTEGER
Language Reference
Description
Data
type
Description
TMP$CSCONVER
T
INTEGER
TMP$DBB
INTEGER
Database block
TMP$DCC
INTEGER
TMP$DFW
INTEGER
TMP$DLS
INTEGER
TMP$EXT
INTEGER
TMP$FIL
INTEGER
TMP$FLD
INTEGER
TMP$FMT
INTEGER
Format block
TMP$FRB
INTEGER
Free block
TMP$FUN
INTEGER
TMP$HNK
INTEGER
TMP$IDB
INTEGER
TMP$IDL
INTEGER
TMP$IRB
INTEGER
TMP$IRL
INTEGER
TMP$LCK
INTEGER
TMP$LWT
INTEGER
TMP$MAP
INTEGER
TMP$MFB
INTEGER
TMP$NOD
INTEGER
TMP$OPT
INTEGER
TMP$PRC
INTEGER
TMP$PRE
INTEGER
TMP$PRM
INTEGER
TMP$REC
INTEGER
Record block
TMP$REL
INTEGER
Relation block
File block
Hunk block
Lock block
Node block
Precedence block
6-43
Data
type
Description
TMP$REQ
INTEGER
Request block
TMP$RIV
INTEGER
TMP$RSB
INTEGER
TMP$RSC
INTEGER
TMP$SAV
INTEGER
TMP$SBM
INTEGER
TMP$SCL
INTEGER
TMP$SDW
INTEGER
TMP$SMB
INTEGER
TMP$SRPB
INTEGER
TMP$STR
INTEGER
TMP$SVC
INTEGER
TMP$SYM
INTEGER
TMP$TEXTTYPE
INTEGER
TMP$TFB
INTEGER
TMP$TPC
INTEGER
TMP$TRA
INTEGER
TMP$USR
INTEGER
TMP$VCL
INTEGER
TMP$VCT
INTEGER
TMP$VCX
INTEGER
TMP$XCP
INTEGER
String block
Transaction block
TMP$POOLS
The TMP$POOLS table contains one row for each current memory pool. A pool is a
collection of memory to support the allocation needs of an internal system object.
6-44
Language Reference
Data type
Description
TMP$POOL_ID
INTEGER
Pool identifier
TMP$TYPE
CHAR[31]
Pool type
TMP$POOL_MEMORY
INTEGER
TMP$FREE_MEMORY
INTEGER
TMP$EXTEND_MEMORY
INTEGER
TMP$FREE_STACK_NODES
SMALLINT
TMP$FREE_BITMAP_BUCKETS
SMALLINT
TMP$FREE_BITMAP_SEGMENT
S
INTEGER
TMP$PROCEDURES
The TMP$PROCEDURES table contains one row for each procedure executed since
the current connection began.
Table 6.41 TMP$PROCEDURES
Column name
Data type
Description
TMP$PROCEDURE_ID
INTEGER
Procedure identifier
TMP$DATABASE_ID
INTEGER
Database identifier
TMP$PROCEDURE_NAME
CHAR[67]
Procedure name
TMP$POOL_ID
INTEGER
Pool identifier
TMP$POOL_MEMORY
INTEGER
TMP$CLONE
SMALLINT
TMP$TIMESTAMP
TIMESTAMP
TMP$USE_COUNT
SMALLINT
TMP$QUANTUM
INTEGER
Units of execution
TMP$INVOCATIONS
INTEGER
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
6-45
Data type
Description
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGE
S
INTEGER
TMP$RECORD_BACKOUT
S
INTEGER
TMP$RELATIONS
The TMP$RELATIONS table contains one row for each relation referenced since the
current connection began.
Table 6.42 TMP$RELATIONS
6-46
Column name
Data type
Description
TMP$RELATION_ID
SMALLINT
Relation identifier
TMP$DATABASE_ID
INTEGER
Database identifier
TMP$RELATION_NAME
CHAR[67]
Relation name
TMP$USE_COUNT
SMALLINT
TMP$SWEEP_COUNT
SMALLINT
TMP$SCAN_COUNT
INTEGER
Sequential scans
TMP$FORMATS
SMALLINT
TMP$POINTER_PAGES
INTEGER
TMP$DATA_PAGES
INTEGER
TMP$GARBAGE_COLLECT_PAGE
S
INTEGER
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
Language Reference
Data type
Description
TMP$RECORD_IDX_SELECTS
INTEGER
TMP$RECORD_SEQ_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGES
INTEGER
TMP$RECORD_BACKOUTS
INTEGER
TMP$STATEMENTS
The TMP$STATEMENTS table contains one row for each statement currently
executing for any current connection.
Table 6.43 TMP$STATEMENTS
Column name
Data type
Description
TMP$STATEMENT_ID
INTEGER
Statement identifier
TMP$ATTACHMENT_ID
INTEGER
Connection identifier
TMP$TRANSACTION_ID
INTEGER
Transaction number
TMP$SQL
VARCHAR[4094]
SQL string
TMP$POOL_ID
INTEGER
Pool identifier
TMP$POOL_MEMORY
INTEGER
TMP$CLONE
SMALLINT
TMP$TIMESTAMP
TIMESTAMP
TMP$QUANTUM
INTEGER
Units of execution
TMP$INVOCATIONS
INTEGER
TMP$STATE
CHAR[31]
TMP$PRIORITY
CHAR[31]
Reserved
TMP$PAGE_READS
INTEGER
6-47
Data type
Description
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGE
S
INTEGER
TMP$RECORD_BACKOUT
S
INTEGER
TMP$TRANSACTIONS
The TMP$TRANSACTIONS table contains one row for each transaction that is active
or in limbo.
Table 6.44 TMP$TRANSACTIONS
6-48
Column name
Data type
Description
TMP$TRANSACTION_ID
INTEGER
Transaction number
TMP$ATTACHMENT_ID
INTEGER
Connection identifier
TMP$POOL_ID
INTEGER
TMP$POOL_MEMORY
INTEGER
TMP$TIMESTAMP
TIMESTAMP
TMP$SNAPSHOT
INTEGER
TMP$QUANTUM
INTEGER
Units of execution
TMP$SAVEPOINTS
INTEGER
TMP$READONLY
CHAR[1]
TMP$WRITE
CHAR[1]
TMP$NOWAIT
CHAR[1]
Transaction is no wait
Language Reference
Data type
Description
TMP$COMMIT_RETAINING
CHAR[1]
TMP$STATE
CHAR[31]
TMP$PRIORITY
CHAR
Reserved
TMP$TYPE
CHAR[31]
SNAPSHOT, READ_COMMITTED
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGES
INTEGER
TMP$RECORD_BACKOUTS
INTEGER
TMP$TRIGGERS
The TMP$TRIGGERS table contains one row for each trigger executed since the
current connection began.
Table 6.45 TMP$TRIGGERS
Column name
Data type
Description
TMP$TRIGGER_ID
INTEGER
Trigger identifier
TMP$DATABASE_ID
INTEGER
Database identifier
TMP$RELATION_NAME
CHAR[67]
TMP$TRIGGER_NAME
CHAR[67]
Trigger name
6-49
6-50
Column name
Data type
Description
TMP$TRIGGER_TYPE
SMALLINT
TMP$TRIGGER_SEQUENCE
SMALLINT
TMP$TRIGGER_ORDER
CHAR[31]
TMP$TRIGGER_OPERATION
CHAR[31]
TMP$POOL_ID
INTEGER
Pool identifier
TMP$POOL_MEMORY
INTEGER
TMP$CLONE
SMALLINT
TMP$TIMESTAMP
TIMESTAMP
TMP$QUANTUM
INTEGER
Units of Execution
TMP$INVOCATIONS
INTEGER
TMP$PAGE_READS
INTEGER
TMP$PAGE_WRITES
INTEGER
TMP$PAGE_FETCHES
INTEGER
TMP$PAGE_MARKS
INTEGER
TMP$RECORD_SELECTS
INTEGER
TMP$RECORD_INSERTS
INTEGER
TMP$RECORD_UPDATES
INTEGER
TMP$RECORD_DELETES
INTEGER
Language Reference
System Views
Data type
Description
TMP$RECORD_PURGES
INTEGER
TMP$RECORD_EXPUNGES
INTEGER
TMP$RECORD_BACKOUTS
INTEGER
System Views
You can create a SQL script using the code provided in this section to create four
views that provide information about existing integrity constraints for a database.
You must create the database prior to creating these views. SQL system views are
a subset of system views defined in the SQL-92 standard. Since they are defined
by ANSI SQL-92, the names of the system views and their columns do not start
with RDB$.
The CHECK_CONSTRAINTS view
CREATE VIEW CHECK_CONSTRAINTS (
CONSTRAINT_NAME,
CHECK_CLAUSE
) AS
SELECT RDB$CONSTRAINT_NAME, RDB$TRIGGER_SOURCE
FROM RDB$CHECK_CONSTRAINTS RC, RDB$TRIGGERS RT
WHERE RT.RDB$TRIGGER_NAME = RC.RDB$TRIGGER_NAME;
The CONSTRAINTS_COLUMN_USAGE view
CREATE VIEW CONSTRAINTS_COLUMN_USAGE (
TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME
) AS
SELECT RDB$RELATION_NAME, RDB$FIELD_NAME,
RDB$CONSTRAINT_NAME
FROM RDB$RELATION_CONSTRAINTS RC, RDB$INDEX_SEGMENTS RI
WHERE RI.RDB$INDEX_NAME = RC.RDB$INDEX_NAME;
The REFERENTIAL_CONSTRAINTS view
CREATE VIEW REFERENTIAL_CONSTRAINTS (
CONSTRAINT_NAME,
UNIQUE_CONSTRAINT_NAME,
MATCH_OPTION,
UPDATE_RULE,
DELETE_RULE
) AS
6-51
System Views
CHECK_CONSTRAINTS
CHECK_CONSTRAINTS identifies all CHECK constraints defined in the database.
Datatype
Length
Description
CONSTRAINT_NAME
CHAR
67
CHECK_CLAUSE
BLOB
CONSTRAINTS_COLUMN_USAGE
CONSTRAINTS_COLUMN_USAGE identifies columns used by PRIMARY KEY and
UNIQUE constraints. For FOREIGN KEY constraints, this view identifies the columns
6-52
Language Reference
System Views
Datatype
Length
Description
TABLE_NAME
CHAR
67
COLUMN_NAME
CHAR
67
CONSTRAINT_NAME
CHAR
67
REFERENTIAL_CONSTRAINTS
REFERENTIAL_CONSTRAINTS identifies all referential constraints defined in a
database.
Table 6.48 REFERENTIAL_CONSTRAINTS
Column name
Datatype
Length
Description
CONSTRAINT_NAME
CHAR
67
UNIQUE_CONSTRAINT_NAME
CHAR
67
MATCH_OPTION
CHAR
UPDATE_RULE
CHAR
11
DELETE_RULE
CHAR
11
6-53
System Views
TABLE_CONSTRAINTS
TABLE_CONSTRAINTS identifies all constraints defined in a database.
6-54
Column name
Datatype
Length
Description
CONSTRAINT_NAME
CHAR
67
TABLE_NAME
CHAR
67
CONSTRAINT_TYPE
CHAR
11
IS_DEFERRABLE
CHAR
INITIALLY_DEFERRED
CHAR
Language Reference
Chapter
Chapter 7
CHAR, VARCHAR, and text Blob columns in InterBase can use many different
character sets. A character set defines the symbols that can be entered as text in a
column, and its also defines the maximum number of bytes of storage necessary
to represent each symbol. In some character sets, such as ISO8859_1, each
symbol requires only a single byte of storage. In others, such as UNICODE_FSS,
each symbol requires from 1 to 3 bytes of storage.
Each character set also has an implicit collation order that specifies how its
symbols are sorted and ordered. Some character sets also support alternative
collation orders. In all cases, choice of character set limits choice of collation
orders.
This chapter lists available character sets and their corresponding collation orders
and describes how to specify:
Default character set for an entire database
Alternative character set and collation order for a particular column in a table
Client application character set that the server should use when translating data
between itself and the client
Collation order for a value in a comparison operation
Collation order in an ORDER BY or GROUP BY clause
7-1
7-2
Character
set
Char.
set ID
Max.
char. size
Min.
char. size
Collation orders
ASCII
1 byte
1 byte
ASCII
BIG_5
56
2 bytes
1 byte
BIG_5
CYRL
50
1 byte
1 byte
CYRL
DB_RUS
PDOX_CYRL
DOS437
10
1 byte
1 byte
DOS437
DB_DEU437
DB_ESP437
DB_FIN437
DB_FRA437
DB_ITA437
DB_NLD437
DB_SVE437
DB_UK437
DB_US437
PDOX_ASCII
PDOX_INTL
PDOX_SWEDFIN
DOS850
11
1 byte
1 byte
DOS850
DB_DEU850
DB_ESP850
DB_FRA850
DB_FRC850
DB_ITA850
DB_NLD850
DB_PTB850
DB_SVE850
DB_UK850
DB_US850
DOS852
45
1 byte
1 byte
DOS852
DB_CSY
DB_PLK
DB_SLO
PDOX_CSY
PDOX_HUN
PDOX_PLK
PDOX_SLO
Language Reference
Char.
set ID
Max.
char. size
Min.
char. size
DOS857
46
1 byte
1 byte
DOS857
DB_TRK
DOS860
13
1 byte
1 byte
DOS860
DB_PTG860
DOS861
47
1 byte
1 byte
DOS861
PDOX_ISL
DOS863
14
1 byte
1 byte
DOS863
DB_FRC863
DOS865
12
1 byte
1 byte
DOS865
DB_DAN865
DB_NOR865
PDOX_NORDAN4
EUCJ_0208
2 bytes
1 byte
EUJC_0208
GB_2312
57
2 bytes
1 byte
GB_2312
ISO8859_1
21
1 byte
1 byte
ISO8859_1
CC_ESPLAT1
CC_PTBRLAT1
DA_DA
DE_DE
DU_NL
EN_UK
EN_US
ES_ES
FI_FI
FR_CA
FR_FR
IS_IS
IT_IT
NO_NO
PT_PT
SV_SV
ISO8859_2
22
1 byte
1 byte
ISO8859_2
CS_CZ
PL_PL
Collation orders
7-3
7-4
Character
set
Char.
set ID
Max.
char. size
Min.
char. size
ISO8859_15
39
1 byte
1 byte
ISO8859_15
DA_DA9
DE_DE9
DU_NL9
EN_UK9
EN_US9
ES_ES9
FI_FI9
FR_CA9
FR_FR9
IS_IS9
IT_IT9
NO_NO9
PT_PT9
SV_SV9
KO18R
58
1 byte
1 byte
RU_RU
KSC_5601
44
2 bytes
1 byte
KSC_5601
KSC_DICTIONARY
NEXT
19
1 byte
1 byte
NEXT
NXT_DEU
NXT_FRA
NXT_ITA
NXT_US
NONE
1 byte
1 byte
NONE
OCTETS
1 byte
1 byte
OCTETS
SJIS_0208
2 bytes
1 byte
SJIS_0208
UNICODE_BE
UCS2BE
2 bytes
2 bytes
UNICODE_FSS
3 bytes
1 byte
UNICODE_FSS
UNICODE_LE
UCS2LE
64
2 byte
2 bytes
N/A
UTF_8
59
4 byte
1 bytes
WIN1250
51
1 byte
1 byte
WIN1250
PXW_CSY
PXW_HUNDC
PXW_PLK
PXW_SLO
WIN1251
52
1 byte
1 byte
WIN1251
PXW_CYRL
Language Reference
Collation orders
Char.
set ID
Max.
char. size
Min.
char. size
WIN1252
53
1 byte
1 byte
WIN1252
PXW_INTL
PXW_INTL850
PXW_NORDAN4
PXW_SPAN
PXW_SWEDFIN
WIN1253
54
1 byte
1 byte
WIN1253
PXW_GREEK
WIN1254
55
1 byte
1 byte
WIN1254
PXW_TURK
Collation orders
7-5
DOS437
437
DOS850
850
DOS852
852
DOS857
857
DOS860
860
DOS861
861
DOS863
863
DOS865
865
The names of collation orders for these character sets that are specific to Paradox
begin PDOX. For example, the DOS865 character set for DOS code page 865
supports a Paradox collation order for Norwegian and Danish called
PDOX_NORDAN4.
The names of collation orders for these character sets that are specific to dBASE
begin DB. For example, the DOS437 character set for DOS code page 437
supports a dBASE collation order for Spanish called DB_ESP437.
For more information about DOS code pages, and Paradox and dBASE collation
orders, see the appropriate Paradox and dBASE documentation and driver books.
Language Reference
7-7
from the database to the client application. Similarly, when the client sends data to
the database, the server translates the data from the clients character set to the
databases default character set (or the character set for an individual column if it
differs from the databases default character set).
For example, the following isql command specifies that isql is using the DOS437
character set. The next command connects to the europe database created
above, in Specifying a Character Set for a Column in a Table:
SET NAMES DOS437;
CONNECT 'europe.ib' USER 'JAMES' PASSWORD 'U4EEAH';
For the complete syntax of SET NAMES, see SET NAMES on page 2-136. For the
complete syntax of CONNECT, see CONNECT on page 2-34.
Language Reference
fragment from an embedded application, the value to the left of the comparison
operator is forced to be compared using a specific collation:
WHERE LNAME COLLATE FR_CA = :lname_search;
For the complete syntax of the WHERE clause, see SELECT on page 2-127.
7-9
7-10
Language Reference
A
access privileges See security
active set (cursors) 2-114
adding
See also inserting
columns 2-17
integrity constraints 2-17
secondary files 2-10
aggregate functions 2-5
AVG() 2-26
COUNT() 2-36
MAX() 2-112
MIN() 2-113
SUM() 2-135
ALTER DATABASE 2-10
ALTER DOMAIN 2-13
ALTER EXCEPTION 2-14
ALTER INDEX 2-15
ALTER PROCEDURE 2-16
ALTER TABLE 2-17
ALTER TRIGGER 2-23
applications
preprocessing See gpre
arithmetic functions See aggregate functions
arrays
See also error status array
viewing dimension information 6-9
assigning values to variables 3-3
assignment statements 3-3
averages 2-26
AVG() 2-26
B
BASED ON 2-26
BEGIN . . . END block
defined 3-3
BEGIN DECLARE SECTION 2-27
BLOB cursors
closing 2-31
declaring 2-78
inserting data 2-111
opening 2-115
BLOB data
converting subtypes 2-82
inserting 2-79, 2-111
selecting 2-79
updating 2-137
BLOB data type 7-1
BLOB filters
declaring 2-81
dropping 2-90
viewing information about 6-15
BLOB segments
host-language variables 2-27
retrieving 2-104
Index
C
Index
I-1
D
data
I-2
Language Reference
inserting 2-109
retrieving 2-102
selecting 2-121, 3-15
sorting 7-1
storing 7-1
updating 2-136
data integrity
adding constraints 2-17, 2-65
dropping constraints 2-17
database cache buffers
increasing/decreasing 2-35
database handles
declaring 2-128
database objects
viewing relationships among 6-6
database pages 2-38
viewing information about 6-21
databases
altering 2-10
connecting to 2-33
creating 2-37
declaring scope of 2-128
decrypting 2-10
detaching 2-87
dropping 2-88
encrypting 2-10
multi-file 2-12
setting access to in SQL 2-127, 2-131, 2-135
shadowing 2-58, 2-94
viewing information about 6-51
datatypes 2-6
converting 2-29
in table columns 2-63
specifying with domains 2-40
date and time information 2-102
DATE datatype 2-102
description 2-6, 2-7
dBASE for DOS 7-5
dBASE for Windows 7-5
DECIMAL datatype 2-6, 2-7
DECLARE CURSOR 2-9, 2-30, 2-77, 2-78
DECLARE CURSOR (BLOB) 2-78
DECLARE EXTERNAL FUNCTION 2-79
DECLARE FILTER 2-81
DECLARE STATEMENT 2-9, 2-30, 2-77, 2-78,
2-82
DECLARE TABLE 2-9, 2-30, 2-64, 2-77, 2-78,
2-83
DECLARE VARIABLE 3-5
declaring
database handles 2-128
error status array 5-3
host-language variables 2-26 to 2-27, 2-96
local variables 3-5
E
-either_case switch 2-116
ENCRYPT ON ENCRYPTION
grant permission to 2-107
F
FETCH 2-102
FETCH (BLOB) 2-104
files
secondary 2-10, 6-14
shadow 6-14
FLOAT datatype 2-6
FOR SELECT . . . DO 3-10
Index
I-3
G
GEN_ID() 2-105
generators
creating 2-45
initializing 2-129
resetting, caution 2-129
returning 2-105
viewing information about 6-17
gpre 2-96
declaring SQLCODE automatically 2-27
-either_case switch 2-116
error status array processing 5-3
-manual switch 2-87, 2-133
gpre directives
BASED ON 2-27
BEGIN DECLARE SECTION 2-27
DECLARE TABLE 2-83
END DECLARE SECTION 2-96
GRANT 2-106
decrypt permission 2-107
encryption permission 2-107
GROUP BY 2-125, 7-1, 7-7, 7-9
H
HAVING 2-125
host-language variables
declaring 2-26 to 2-27, 2-96
I
I/O See input, output
IF . . . THEN . . . ELSE 3-11
indexes
activating/deactivating 2-15
altering 2-15
columns comprising 6-18
creating 2-46
dropping 2-91
recomputing selectivity 2-131
viewing structures of 6-18
indicator variables 2-101
I-4
initializing
generators 2-129
input parameters 2-52
defined 3-12
input statements 2-86
INSERT 2-109, 3-12
INSERT CURSOR (BLOB) 2-111
inserting
See also adding
new rows 2-109
INTEGER datatype 2-6
integrity constraints
See also specific type
adding 2-17, 2-65
cascading 2-21, 2-22, 2-63, 2-65, 2-66
dropping 2-17
types 2-65
viewing information about 6-23, 6-51
Interactive SQL See isql
international character sets 7-1 to 7-9
additional 7-6
default 7-7
specifying 7-7 to 7-8
INTO 2-125
isc_convert_error 5-4
isc_deadlock 5-4
isc_integ_fail 5-4
isc_lock_conflict 5-4
isc_no_dup 5-4
isc_not_valid 5-4
isc_print_sqlerror() 5-3
isc_sql_interprete() 5-3
isc_status 5-3
ISOLATION LEVEL 2-134
Language Reference
journal archiving
activating 2-49
journal archiving, dropping 2-92
journal files
activating 2-47
deleting 2-92
journaling
activating 2-47
dropping 2-92
K
key constraints See FOREIGN KEY constraints;
PRIMARY KEY constraints
keys
defined 2-65
keywords 4-1 to 4-4
M
-manual switch 2-87, 2-133
MAX() 2-112
maximum values 2-112
messages 5-1 to 5-37
metadata 6-1
MIN() 2-113
minimum values 2-113
modifying See altering;updating
MS-DOS code pages 7-5
multi-file databases
creating 2-12
multiple transactions
running 2-133
N
naming conventions
keywords and 4-1
nested stored procedures 3-7
NEW context variables 3-12 to 3-13
NO RECORD_VERSION 2-134
NO WAIT 2-133
nomenclature
stored procedures and triggers 3-2
numbers
averaging 2-26
calculating totals 2-135
NUMERIC datatype 2-7
numeric function 2-6, 2-105
numeric values See values
O
object delimiter 2-2
OLD context variables 3-13
OPEN 2-114
OPEN (BLOB) 2-115
ORDER BY 2-46, 2-76, 2-84, 2-124, 2-125, 2-137,
7-1, 7-7, 7-9
output
error messages 5-3
output parameters 2-52
defined 3-14
R
RDB$CHARACTER_SETS 6-3
RDB$CHECK_CONSTRAINTS 6-4
RDB$COLLATIONS 6-4
RDB$DATABASE 6-5
RDB$DEPENDENCIES 6-6
RDB$EXCEPTIONS 6-9
RDB$FIELD_DIMENSIONS 6-9
RDB$FIELDS 6-9
RDB$FILES 6-14
RDB$FILTERS 6-15
RDB$FORMATS 6-15
RDB$FUNCTION_ARGUMENTS 6-16
RDB$FUNCTIONS 6-17
RDB$GENERATORS 6-17
RDB$INDEX_SEGMENTS 6-18
RDB$INDICES 6-18
RDB$LOG_FILES 6-21
RDB$PAGES 6-21
RDB$PROCEDURE_PARAMETERS 6-21
RDB$PROCEDURES 6-22
RDB$REF_CONSTRAINTS 6-23
RDB$RELATION_CONSTRAINTS 6-23
RDB$RELATION_FIELDS 6-24
RDB$RELATIONS 6-26
RDB$SECURITY_CLASSES 6-30
RDB$TRANSACTIONS 6-30
RDB$TRIGGER_MESSAGES 6-31
RDB$TRIGGERS 6-31
Index
I-5
RDB$TYPES 6-33
RDB$USER_PRIVILEGES 6-33, 6-34
RDB$VIEW_RELATIONS 6-35
READ COMMITTED 2-134
read-only transactions
committing 2-32
read-only views 2-76
RECORD_VERSION 2-134
recursive stored procedures 3-7
REFERENCES constraint 2-65
referential integrity See integrity constraints
REFERENTIAL_CONSTRAINTS system
view 6-51
RELEASE argument 2-32
RELEASE SAVEPOINT 2-117
repetitive statements 3-10, 3-20
repetitive tasks 3-7
reserved words See keywords
RESERVING clause 2-134
retrieving data 2-102
REVOKE 2-117
decrypt permission 2-119
encryption permission 2-119
roles
creating 2-57
dropping 2-93
granting 2-106
revoking 2-117
system table 6-29
ROLLBACK 2-120
rows
deleting 2-84
inserting 2-109
selecting 2-102
stored procedures and triggers 3-15
sequentially accessing 2-103
updating 2-136
ROWS clause 2-121
run-time errors 5-1
S
savepoints
creating and using 2-121
releasing 2-117
roll back to 2-120
search conditions (queries)
comparing values 3-15
evaluating 2-114
secondary files 2-38
adding 2-10
viewing information about 6-14
secondary storage devices 2-59
security
I-6
Language Reference
T
TABLE_CONSTRAINTS system view 6-51
tables
altering 2-17
creating 2-60
declaring 2-83
dropping 2-94
inserting rows 2-109
viewing information about 6-23, 6-26, 6-51
tasks, repetitive 3-7
text 7-1
TIME datatype 2-102
TIMESTAMP datatype 2-102
totals, calculating 2-135
transaction names 2-133
transactions
committing 2-31
default 2-133
multiple databases 6-30
read-only 2-32
rolling back 2-120
running multiple 2-99, 2-100, 2-133
starting 2-132
transition features 2-2
trapping
errors 2-138, 3-18, 5-2
warnings 2-138, 5-2
trigger language 3-2
triggers 3-3
altering 2-23
creating 2-67, 3-1
dropping 2-95
error handling 3-18
U
UDFs 6-17
declaring 2-79
dropping 2-90
UNION 2-125
UNION operator 3-16
UNIQUE constraints
viewing information about 6-50
UNIQUE keys 2-65
UPDATE 2-136, 3-12, 3-13
updating
BLOB data 2-137
rows 2-136
UPPER() 2-138
uppercase, converting to 2-138
USER name 2-63, 2-66
user-defined errors See exceptions
user-defined functions See UDFs
USING clause 2-134
V
values
See also NULL values
assigning to variables 3-3
averages 2-26
changing 3-12
maximum 2-112
minimum 2-113
passing to stored procedures 3-12
returning 3-14, 3-16
to SQLCODE variable 2-9
totals 2-135
VARCHAR data type 7-1
VARCHAR datatype 2-7
variables
context 3-12 to 3-14
host-language 2-26 to 2-27, 2-96
indicator 2-101
local 3-3, 3-5
views
creating 2-75
dropping 2-96
read-only 2-76
updatable 2-76
viewing characteristics of 6-26
Index
I-7
W
WAIT 2-133
warnings
See also errors
trapping 2-138, 5-2
WHEN 2-45
WHEN . . . DO 3-18
I-8
Language Reference