RDB/VMS SQL DECLARE — VMS RDB_4.0B
Specifies a cursor, database, table, statement, or transaction to VAX SQL.
Additional information available:
CURSORDATABASESCHEMASTATEMENTTABLETRANSACTION
CURSOR
Specifies a cursor that identifies a result table or a list. DECLARE cursor-name ─┬────────────────┬──┐ ├─>
I
N
S
E
R
T
O
N
L
Y ─┤ │ └─>
R
E
A
D
O
N
L
Y ───┘ │ ┌────────────────────────────────────────┘ ├┬─────────┬─>
C
U
R
S
O
R
F
O
R ──> select-expr ──┐ │└>
T
A
B
L
E ─┘ │ │ ┌───────────────────────────────────┘ │ └─┬────────────────────┬─┬─────────────────────┬─┐ │ └─> order-by-clause ─┘ └─> limit-to-clause ──┘ │ │ ┌────────────────────────────────────────────────┘ │ └─┬─────────────────────────────────────┬──────────┬──> typebox (;) │ └─>
F
O
R
U
P
D
A
T
E
O
F ─┬─> column-name ─┬─┘ │ │ └────── , <──────┘ │ │ │ └─>
L
I
S
T
C
U
R
S
O
R
F
O
R
S
E
L
E
C
T ───> column-name ────┐ │ │ │ ┌───────────────────────────────────────┘ │ │ │ └─>
W
H
E
R
E
C
U
R
R
E
N
T
O
F ───> table-cursor-name ───────┘
Additional information available:
INSERT_ONLYREAD_ONLYFOR_UPDATE_OFLIST_CURSOR
WHERE_CURRENT_OF
More Informationselect exprorder by clauselimit to clause
INSERT_ONLY
Insert-only cursors position themselves on a row that has just been inserted so that you can load data values into lists or rows of that row.
READ_ONLY
Read-only cursors can be used to access row information from a result table whenever you do not intend to update the database. For example, you could use a read-only cursor to fetch row and column information for display.
More Information
The DECLARE CURSOR statement defines a cursor, a result table that
exists through execution of more than one SQL statement. Host
language programs require cursors to individually process rows in a
result table.
The result table is created by an OPEN statement. FETCH and CLOSE
statements can operate on a cursor after it is opened.
You can create cursors using three classes of the DECLARE CURSOR
statement:
o The static DECLARE CURSOR statement is executed immediately.
o The Dynamic DECLARE CURSOR statement is also executed
immediately. You can precompile the dynamic DECLARE STATEMENT or
use it as part of the declare statement section in an SQL module.
The cursor name is known at compile time and the select statement
is determined at run time. You must supply a parameter for the
cursor name.
o The Extended Dynamic DECLARE CURSOR statement must be precompiled
or used as part of a procedure in the SQL module. You must
supply parameters for the cursor name and for the identifier of a
prepared SELECT statement that is prepared at run time.
SQL provides two types of cursor: table cursors (the default) and
list cursors.
o Use table cursors to access individual rows of a result tables.
o Use list cursors to access individual elements in a list. For
details about lists, see the section on LIST_CURSOR.
Cursors can be further classified according to the modes of
operations that you can use them for.
o Use update table cursors (the default) to modify table rows.
o Use read-only cursors to access row or list element information
that you do not intend to update.
o Use insert-only cursors to insert data values into a row or list
element.
FOR_UPDATE_OF
Specifies the columns in a cursor that you or your program might
later modify with an UPDATE statement. The column names in the FOR
UPDATE clause must belong to a table or view named in the FROM
clause.
You do not have to specify the FOR UPDATE clause of the DECLARE
CURSOR statement to later modify rows using the UPDATE statement.
However, if you do specify FOR UPDATE and later specify columns in an
UPDATE statement that are not in the FOR UPDATE clause, VAX SQL
issues a warning message and proceeds with the update modifications.
If you do not specify a FOR UPDATE clause, you can update any column
using the UPDATE statement. VAX SQL will not issue any messages.
SQL considers as read-only cursors those that:
o Use the DISTINCT argument to eliminate duplicate rows from the
result table
o Name more than one table or view in the FROM clause
o Include a function in the select list
o Contain a GROUP BY or HAVING clause
o Contain an ORDER BY clause
With the exception of cursors containing an ORDER BY clause, you
cannot refer to read-only cursors in UPDATE or DELETE statements.
select expr
select-expr =
───┬─┬─> select-clause ─────┬───>
│ └─>( select-expr ) ────┤
│ ┌─────────<────────────┘
│ └─>
U
N
I
O
N ─┬───────┬────┐
│ └─>
A
L
L ─┘ │
└───────<────────────────┘
Additional information available:
select clause
select-clause = SELECT ─┬──────>──────┬─> select-list ──┐ ├─>
A
L
L ──────┤ │ └─>
D
I
S
T
I
N
C
T ─┘ │ ┌──────────────────────────────<──────┘ └
F
R
O
M ─┬┬─> table-name ─┬─┬─────>────┬─┬─┬─────────>──────────┬─┐ │└─> view-name ──┘ └─> alias ─┘ │ └─>
W
H
E
R
E predicate ─┘ │ └────────── , <─────────────────┘ │ ┌──────────────────────────────<─────────────────────────────────┘ └┬─────────────>──────────────────┬─┬──────────>──────────┬──> └─>
G
R
O
U
P
B
Y ─┬─> column-name ─┬─┘ └─>
H
A
V
I
N
G predicate ─┘ └─────── , <─────┘
order by clause
order-by-clause = ──>
O
R
D
E
R
B
Y ─┬┬─> column-name ─┬─┬────>────┬─┬──> │└─> integer ─────┘ ├─>
A
S
C ──┤ │ │ └─>
D
E
S
C ─┘ │ └──────────── , <───────────────┘
limit to clause
limit-to-clause = ───>
L
I
M
I
T
T
O ────> row-limit ───>
R
O
W
S ──>
LIST_CURSOR
Specifies a cursor used to access lists, as opposed to a table cursor. A list is an ordered collection of elements of the data type LIST OF VARBYTE (also called LIST OF BYTE VARYING). A list is equivalent to an RDO segmented string. You can use lists to scan through very large data structures from within a language that does not support objects of such size. Lists exist as a set of elements within a row of a table. Each list cursor must reference a table cursor, which provides the row context. 4 Examples
Additional information available:
Examples
Example 1: Creating a table that contains a list.
SQL> CREATE TABLE RESUMES
(FIRST_NAME CHAR(10),
cont> LAST_NAME CHAR(14),
cont> RESUME LIST OF VARBYTE);
Example 2: Showing a table that contains a list.
SQL> SHOW TABLE RESUMES;
Columns for table RESUMES:
Column Name Data Type Domain
----------- --------- ------
FIRST_NAME CHAR(10)
LAST_NAME CHAR(14)
RESUME VARBYTE LIST
Segment Length: 512
Table constraints for RESUMES:
No constraints found
Constraints referencing table RESUMES:
No constraints found
Storage Map for table RESUMES:
No Storage Map found
Triggers on table RESUMES:
No triggers found
Example 3: Inserting data into a list.
SQL> DECLARE TBLCURSOR INSERT ONLY TABLE CURSOR FOR SELECT EMPLOYEE_ID,
cont> RESUME FROM RESUMES;
SQL> DECLARE LSTCURSOR INSERT ONLY LIST CURSOR FOR SELECT RESUME
cont> WHERE CURRENT OF TBLCURSOR;
SQL> OPEN TBLCURSOR;
SQL> INSERT INTO CURSOR TBLCURSOR (EMPLOYEE_ID) VALUES ("00167");
1 row inserted
SQL> OPEN LSTCURSOR;
SQL> INSERT INTO CURSOR LSTCURSOR VALUES ("This is the resume for 00167");
SQL> INSERT INTO CURSOR LSTCURSOR VALUES ("Boston, MA");
SQL> INSERT INTO CURSOR LSTCURSOR VALUES ("Digital Equipment Corporation");
SQL> CLOSE LSTCURSOR;
SQL> CLOSE TBLCURSOR;
SQL> COMMIT;
Example 3: Displaying data from a list.
SQL> DECLARE TBLCURSOR2 CURSOR FOR SELECT EMPLOYEE_ID, RESUME FROM RESUMES;
SQL> DECLARE LSTCURSOR2 LIST CURSOR FOR SELECT RESUME
cont> WHERE CURRENT OF TBLCURSOR2;
SQL> OPEN TBLCURSOR2;
SQL> FETCH TBLCURSOR2;
00167
SQL> OPEN LSTCURSOR2;
SQL> FETCH LSTCURSOR2;
RESUME
This is the resume for 00167
SQL> FETCH LSTCURSOR2;
RESUME
Boston, MA
SQL> FETCH LSTCURSOR2;
RESUME
Digital Equipment Corporation
SQL> FETCH LSTCURSOR2;
RESUME
%RDB-E-STREAM_EOF, attempt to fetch past end of record stream
SQL> CLOSE LSTCURSOR2;
SQL> CLOSE TBLCURSOR2;
Example 4: Displaying the segmented string (list) identifier
SQL> SELECT * FROM RESUMES;
EMPLOYEE_ID RESUME
00167 1:701:2
1 row selected
WHERE_CURRENT_OF
Specifies the table cursor that provides the row context for the list cursor. The table cursor must be defined using a DECLARE CURSOR statement.
DATABASE
The DECLARE DATABASE statement is supported only for upward compatibility. For information on declaring databases see the Help topic on DECLARE SCHEMA.
SCHEMA
DECLARE ─┬──────>──────┬─┬───────>────┬─>
S
C
H
E
M
A typebox (A)typebox (U)typebox (T)typebox (H)typebox (O)typebox (R)typebox (I)typebox (Z)typebox (A)typebox (T)typebox (I)typebox (O)typebox (N) ─┐ ├─>
L
O
C
A
L ────┤ └─> auth-id ─┘ │ ├─>
G
L
O
B
A
L ───┤ │ └─>
E
X
T
E
R
N
A
L ─┘ │ ┌───────────────────────────────────────────────────────────────┘ └─> Ftypebox (O)typebox (R) ─┬─────────>─────────┬──┬──>
P
A
T
H
N
A
M
E ───> path-name ─┬─┐ └──> typebox (C)typebox (O)typebox (M)typebox (P)typebox (I)typebox (L)typebox (E)typebox (T)typebox (I)typebox (M)typebox (E) ───┘ └──>
F
I
L
E
N
A
M
E ───> file-spec ─┘ │ ┌──────────────────────────── <─────────────────────────────────┘ └──┬────────────────────> ─────────────────────────┬──┐ └──>
R
U
N
T
I
M
E ──┬─>
F
I
L
E
N
A
M
E ─┬──> file-spec ──┬─┤ │ │ └──> parameter ──┘ │ │ └─>
P
A
T
H
N
A
M
E ─┬──> path-name ──┬─┘ │ └──> parameter ──┘ │ ┌──────────────────────────<──────────────────────────┘ └──┬──────────────────────>─────────────────┬──┬───────────┬────>typebox (;) └>
D
B
K
E
Y typebox (S)typebox (C)typebox (O)typebox (P)typebox (E) typebox (I)typebox (S) ──┬──>
A
T
T
A
C
H ──────┬──┘ ├─>
V
I
D
A ───┤ └──>
T
R
A
N
S
A
C
T
I
O
N ─┘ └─>
N
O
V
I
D
A ─┘
Additional information available:
More Information
The DECLARE SCHEMA statement specifies the name and the source of the schema definitions to be accessed in a program or by interactive SQL. If you do not declare any schema, SQL declares the schema specified in the logical name SQL$DATABASE as the default schema, using the FOR FILENAME clause. See the Help topic on default_schema for more information.
STATEMENT
DECLARE ──┬─> statement-name ──┬─>
S
T
A
T
E
M
E
N
T typebox (;) └─────── , <────────┘
Additional information available:
More Information
DECLARE STATEMENT is used only in preprocessed programs that include dynamic SQL. DECLARE STATEMENT documents a statement name later used in a PREPARE, DECLARE CURSOR, or DESCRIBE statement. Including the DECLARE STATEMENT is optional.
TABLE
DECLARE ──┬─> table-name ─┬─>
T
A
B
L
E ──┐ └─> view-name ──┘ │ ┌───────────────────────────────────┘ └─> ( ─┬┬─> declare-col-definition ─┬┬─> ) ──> typebox (;) │└─> table-constraint ───────┘│ └────────── , <───────────────┘
Additional information available:
More Informationdeclare col definitiontable constraint
More Information
The DECLARE TABLE statement is used in preprocessed programs and as part of SQL module procedures. It is an alternative to SQL's implicit declaration of a table based on the table definition in the database file or data dictionary. For a table named in a DECLARE TABLE statement, SQL does not check the database or dictionary to compare the table definition with the explicit declaration. The DECLARE TABLE statement documents a table definition in the source code of the program. It allows program references to tables that are created by other modules of a program or that are created dynamically. Using DECLARE TABLE can also improve precompiler or module processor performance because SQL does not have to retrieve the table definition from the database. You can also use DECLARE TABLE to specify a subset of a table definition when the program needs to use only some of the columns in the table. For details on specifying column definitions and table constraints, see the Help topic on CREATE TABLE.
declare col definition
declare-col-definition =
──> column-name ──> data-type ─┬┬──────────>─────────────┬┬─>
│├─> col-constraint ──────┤│
│└─> sql-and-dtr-clause ──┘│
└───────────<──────────────┘
The definition for a column in the table. The column definition must
correspond to a table definition in the schema.
Additional information available:
column namedata typecol constraintsql and dtr clause
column name
The name of the column you are defining.
data type
data-type = ──┬─>
C
H
A
R ─┬────────┬───────────────────────────┬──> │ └─> (n) ─┘ │ ├─>
V
A
R
C
H
A
R (n) ───────────────────────────────┤ ├─>
L
O
N
G
V
A
R
C
H
A
R ──────────────────────────────┤ ├─>
T
I
N
Y
I
N
T ──────────────┬─────┬────────┬─────┤ ├─>
S
M
A
L
L
I
N
T ─────────────┤ └─> (n) ─┘ │ ├─>
I
N
T
E
G
E
R ──────────────┤ │ ├─>
Q
U
A
D
W
O
R
D ─────────────┤ │ ├─>
L
I
S
T
O
F
B
Y
T
E
V
A
R
Y
I
N
G ─┘ │ ├─>
D
E
C
I
M
A
L ─┬─┬─────────────────────────────┬─┤ ├─>
N
U
M
E
R
I
C ─┘ └─> ( ──> n ─┬────────┬─> ) ──┘ │ │ └─> , n ─┘ │ ├─>
F
L
O
A
T ─┬────────┬──────────────────────────┤ │ └─> (n) ─┘ │ ├─>
R
E
A
L ──────────────────────────────────────┤ ├─>
D
O
U
B
L
E
P
R
E
C
I
S
I
O
N ──────────────────────────┤ └─>
D
A
T
E ──────────────────────────────────────┘ The data type of the column you are defining.
col constraint
col-constraint = ─┬─>
P
R
I
M
A
R
Y
K
E
Y ──────────────────────┬──┐ ├─>
N
O
T
N
U
L
L ─────────────────────────┤ │ ├─>
U
N
I
Q
U
E ───────────────────────────┤ │ ├─>
C
H
E
C
K (predicate) ────────────────┤ │ └─> references-clause ────────────────┘ │ ┌───────────────────────<────────────────┘ └─┬─────────────────>─────────────┬─> └─>
C
O
N
S
T
R
A
I
N
T constraint-name ─┘
Additional information available:
More Informationreferences clause
More Information
A col-constraint is a constraint definition that applies to the
specified column. The five types of column constraints are PRIMARY
KEY, NOT NULL, UNIQUE, CHECK, and foreign key constraints. Foreign
key constraints are created with the REFERENCES clause. You can also
optionally specify a name for a constraint definition.
The PRIMARY KEY column constraint declares a column to be a primary
key. SQL requires that values in this column be unique and not null.
Therefore, you need not specify the UNIQUE and NOT NULL column
constraints for a primary key column.
The NOT NULL column constraint restricts values in the column to
non-null values.
The UNIQUE column constraint specifies that values in the column
named must be unique. You can use either UNIQUE or PRIMARY KEY
keywords to define a column as a unique key for a table.
The CHECK column constraint specifies a predicate that column values
inserted into the table must satisfy. Predicates in CHECK table
constraints can refer directly only to the column with which they are
associated.
The optional CONSTRAINT constraint-name specifies a name for a column
constraint that is used in several ways:
o The INTEG_FAIL error message specifies the name when an INSERT,
UDPATE, or DELETE statement violates the constraint
o ALTER TABLE DROP CONSTRAINT statements specify the name to drop a
table constraint
o SHOW TABLE statements display the names of column and table
constraints
The name of the constraint is used in error messages and ALTER TABLE
DROP CONSTRAINT, SHOW TABLE, DECLARE TRANSACTION and SET TRANSACTION
statements. The CONSTRAINT clause is optional. If you omit the
constraint name, SQL creates a name. However, DIGITAL recommends
that you always name column and table constraints. The constraint
names generated by SQL may be obscure and, in programs, may change
between compilation and running.
references clause
references-clause =
REFERENCES referenced-table-name ───┐
┌─────────────────<────────────────┘
└─┬─────────────────────>───────────────────┬─>
└─> ( ─┬─> referenced-column-name ─┬─> ) ─┘
└─────────── , <────────────┘
Specifies the name of a column or columns that are a unique key or
primary key in the referenced table. When the REFERENCES clause is
selected as a column-constraint, the column specified in the
col-definition clause becomes a foreign key for the referencing table
(the table being defined). When the REFERENCES clause is selected as
a table constraint, the column name or column names specified in the
FOREIGN KEY clause become a foreign key for the referencing table.
The referenced_table_name is the name of the table that contains the
unique key or primary key referenced by the referencing table. You
must have the SQL access right REFERENCES or CREATETAB to the
referenced table.
For a column constraint, the referenced_column_name is the name of
the column that is a unique key or primary key in the referenced
table. For a table constraint, the the referenced_column_name is the
name of the column or columns that are a unique key or primary key in
the referenced table. The unique key can be defined with either the
UNIQUE or PRIMARY KEY keywords. If you omit the
referenced_column_name, the primary key is selected by default.
sql and dtr clause
sql-and-dtr-clause = ─┬─>
Q
U
E
R
Y
H
E
A
D
E
R typebox (I)typebox (S) ─┬> quoted-string ──┬─────────────────┬─> │ └────── typebox (/) <────────┘ │ ├─>
E
D
I
T
S
T
R
I
N
G typebox (I)typebox (S) quoted-string ─────────────────────────┤ │ │ ├─>
Q
U
E
R
Y
N
A
M
E Ftypebox (O)typebox (R) ─┬─> typebox (D)typebox (T)typebox (R) ────────┬─> typebox (I)typebox (S) quoted-string ─┤ │ └─> typebox (D)typebox (A)typebox (T)typebox (A)typebox (T)typebox (R)typebox (I)typebox (E)typebox (V)typebox (E) ─┘ │ ├─>
D
E
F
A
U
L
T
V
A
L
U
E Ftypebox (O)typebox (R) ─┬─> typebox (D)typebox (T)typebox (R) ────────┬─> typebox (I)typebox (S) literal ────┤ │ └─> typebox (D)typebox (A)typebox (T)typebox (A)typebox (T)typebox (R)typebox (I)typebox (E)typebox (V)typebox (E) ─┘ │ ├─>
N
O
Q
U
E
R
Y
H
E
A
D
E
R ──────────────────────────────────────┤ ├─>
N
O
E
D
I
T
S
T
R
I
N
G ───────────────────────────────────────┤ ├─>
N
O
Q
U
E
R
Y
N
A
M
E ────┬──> Ftypebox (O)typebox (R) ─┬─> typebox (D)typebox (T)typebox (R) ────────┬─────────┘ └─>
N
O
D
E
F
A
U
L
T
V
A
L
U
E ─┘ └─> typebox (D)typebox (A)typebox (T)typebox (A)typebox (T)typebox (R)typebox (I)typebox (E)typebox (V)typebox (E) ─┘ Optional formatting clauses allow you to modify data displays or query characteristics for interactive SQL users and DATATRIEVE users. A query header specifies a string that interactive SQL or DATATRIEVE displays in place of the column name when it retrieves values from a column. An edit string specifies a string that controls how interactive SQL or DATATRIEVE formats the display of values in a column. DEFAULT VALUE and QUERY NAME are active only from DATATRIEVE.
table constraint
table-constraint = ─┬─>
P
R
I
M
A
R
Y
K
E
Y ─> ( ─┬─> column-name ─┬─> ) ──────┬──┐ │ └─────── , <─────┘ │ │ ├─>
U
N
I
Q
U
E ─> ( ─┬─> column-name ─┬─> ) ───────────┤ │ │ └─────── , <─────┘ │ │ ├─>
C
H
E
C
K (predicate) ─────────────────────────────┤ │ └─>
F
O
R
E
I
G
N
K
E
Y ─> ( ─┬─> column-name ─┬─> ) ──┐ │ │ └─────── , <─────┘ │ │ │ ┌───────────────────────<────────────────────┘ │ │ └─> references-clause ─────────────>─────────────┘ │ ┌──────────────────<────────────────────────────────┘ └─┬───────────────────────────────┬─> └─>
C
O
N
S
T
R
A
I
N
T constraint-name ─┘
Additional information available:
More Informationreferences clause
More Information
A table-constraint is a constraint definition that applies to the
whole table. The four types of table constraints are PRIMARY KEY,
UNIQUE, CHECK, and FOREIGN KEY constraints. You can also optionally
specify a constraint name.
The PRIMARY KEY constraint is used to declare a column or columns as
a primary key for the table being defined. Any foreign key that
refers to this column must refer to this primary key.
The UNIQUE table constraint specifies that the combination of values
for the columns named must be unique in a row. Columns named in the
list must be defined with the NOT NULL column constraint. A unique
key can be defined with either the UNIQUE or PRIMARY KEY keywords.
The CHECK table constraint specifies a predicate that column values
inserted into the table must satisfy. Predicates in CHECK table
constraints can refer to any column in the table. Column select
expressions within the predicate can refer to other tables in the
schema.
The FOREIGN KEY table constraint specifies the column or columns that
you want to declare as a foreign key in the table you are defining.
The optional CONSTRAINT constraint-name clause specifies a name for a
column or table constraint. The name specified is used in several
ways:
o The INTEG_FAIL error message specifies the name when an INSERT,
UDPATE, or DELETE statement violates the constraint
o ALTER TABLE DROP CONSTRAINT statements specify the name to drop a
table constraint
o SHOW TABLE statements display the names of column and table
constraints
references clause
references-clause =
REFERENCES referenced-table-name ───┐
┌─────────────────<────────────────┘
└─┬─────────────────────>───────────────────┬─>
└─> ( ─┬─> referenced-column-name ─┬─> ) ─┘
└─────────── , <────────────┘
Specifies the name of a column or columns that are a primary key or
unique key in the referenced table. When the REFERENCES clause is
selected as a column-constraint, the column specified in the
col-definition clause becomes a foreign key for the referencing table
(the table being defined). When the REFERENCES clause is selected as
a table constraint, the column name or column names specified in the
FOREIGN KEY clause become a foreign key for the referencing table.
The referenced_table_name is the name of the table that contains the
unique key or primary key referenced by the referencing table. You
must have the SQL access right REFERENCES or CREATETAB to the
referenced table.
For a column constraint, the referenced_column_name is the name of
the column that is a unique key or primary key in the referenced
table. For a table constraint, the referenced_column_name is the
name of the column or columns that are a unique key or primary key in
the referenced table. If you do not supply a referenced_column_name,
the primary key in the referenced table is used by default.
TRANSACTION
DECLARE TRANSACTION ──┬───────────────┬─> typebox (;) ├─> tx-options ─┤ └─> db-txns ────┘
Additional information available:
More Informationtx optionsdb txns
More Information
Specifies the characteristics for a default transaction. A transaction is a group of statements whose changes can be made permanent or undone as a unit. By default, SQL starts transactions with the characteristics READ WRITE, WAIT, and CONSISTENCY LEVEL 3, reserving tables as required for statements that refer to the tables. In contrast to the SET TRANSACTION statement, the DECLARE TRANSACTION statement is not executable and therefore does not start a transaction. The declarations in a DECLARE TRANSACTION statement take effect when SQL starts an implicit transaction, that is, with the first executable data manipulation or data definition statement following the DECLARE TRANSACTION, COMMIT, or ROLLBACK statement. The characteristics specified in a DECLARE TRANSACTION statement affect all transactions (except those started by the SET TRANSACTION statement) until you issue another DECLARE TRANSACTION statement. The characteristics specified in a SET TRANSACTION statement affect only that transaction. If you end the transaction with a COMMIT statement, all changes made to the database by statements in the transaction are made permanent. If you end the transaction with a ROLLBACK statement, none of the changes made to the database by the statements takes effect. If you then start another transaction with a data manipulation or data definition statement, that transaction also has the characteristics originally specified in the DECLARE TRANSACTION statement. In interactive SQL, you can change transaction characteristics with another DECLARE or SET TRANSACTION statement, but only if a transaction is not currently active. In programs, DECLARE TRANSACTION can apply only one set of transaction characteristics to a precompiled source file or compiled SQL module.
tx options
tx-options = ─┬───>
B
A
T
C
H
U
P
D
A
T
E ───────────>───────────────────────────┬─> └─┬──────────────────┬─┬──────>───────────────────────┬─┐ │ ├─>
R
E
A
D
O
N
L
Y ──┤ ├─>
W
A
I
T ─┬─────────>────────┬─┤ │ │ └─>
R
E
A
D
W
R
I
T
E ──┘ │ └─> timeout-value ─┘ │ │ │ └─>
N
O
W
A
I
T ────────────────────┘ │ │ ┌──────────────────────<──────────────────────────────┘ │ └─┬────────────────────>─────────┬───┐ │ └─>
C
O
N
S
I
S
T
E
N
C
Y
L
E
V
E
L ─┬─> 2 ──┤ │ │ └─> 3 ──┘ │ │ ┌────────────────────────────────────┘ │ └─┬─────────────────>───────────────────────┬─┐ │ └─>
E
V
A
L
U
A
T
I
N
G ─┬─> evaluating-clause ──┬─┘ │ │ └──────── , <───────────┘ │ │ ┌─────────────────────────────────────────────┘ │ └─┬─────────────────>───────────────────────┬─────>─────┘ └─>
R
E
S
E
R
V
I
N
G ──┬─> reserving-clause ───┬─┘ └──────── , <───────────┘
Additional information available:
More Information
The transaction options include:
o BATCH UPDATE to reduce overhead in large load operations by not
writing to any journal files. No rollback is possible for batch
update transactions.
o READ ONLY or READ WRITE specifies whether you want to use a
snapshot of the database for only reading records or use a
locking mechanism of SQL to get consistency in data retrieval and
update for reading and writing records.
o WAIT or NOWAIT determines what your transaction does when it
encounters a locked record. WAIT waits for other transactions to
complete and then proceds. NOWAIT returns an error message when
it encounters a locked record.
o See More_Options for additional transaction options.
Additional information available:
More Options
o CONSISTENCY LEVEL determines the extent to which the database
protects the consistency of your data. Relationships between
data items may not be preserved by LEVEL 2 transactions since
data items can be updated by another transaction before the LEVEL
2 transaction finishes. LEVEL 3 transactions mean the database
system guarantees that data you read will not be changed by
another user before you issue a COMMIT statement.
o EVALUATING determines the point at which the named constraint(s)
are evaluated. If you specify VERB TIME, they are evaluated when
the data manipulation statement is issued. If you specify COMMIT
TIME, they are evaluated when the COMMIT statement executes. For
READ ONLY transactions, this clause is allowed but meaningless.
o RESERVING specifies the list of tables to be locked during the
transaction.
db txns
db-txns = ─┬──────────────────────────────────────────────────────────────┬─> └┬─>
O
N ─┬─> auth-id ─┬─>
U
S
I
N
G ──> (─┬─> tx-options ──┬─> ) ─┬┘ │ └──── , <────┘ └─>
D
E
F
A
U
L
T
S ────┘ │ └──────────────────────────
A
N
D <────────────────────────────┘
Additional information available:
More Information
Specifies the options for accessing other schemas when using the declare transaction statement. These options include the authorization identifier for the schema and whether you want to state the transaction options individually or accept the default transaction options of READ WRITE WAIT plus the consistency option appropriate for the database system you are using.