RDB/VMS SQL DECLARE — VMS SQLdev_2.0
Specifies a cursor, database, table, statement, or transaction to VAX SQL.
Additional information available:
CURSORDATABASESCHEMASTATEMENTTABLETRANSACTION
CURSOR
DECLARE cursor-name CURSOR FOR ──┐ ┌────────────────────────────────┘ ├─> select-expr ──┐ │ ┌───────────────┘ │ └─┬─────────────────────┬─┬─────────────────────────────────────┬─┬─> │ └─> order-by-clause ──┘ └─>
F
O
R
U
P
D
A
T
E
O
F ─┬─> column-name ─┬─┘ │ │ └────── , <──────┘ │ └─> statement-name ─────────────────────────────────────────────────┘ order-by-clause = ──>
O
R
D
E
R
B
Y ─┬┬─> column-name ─┬─┬────>────┬─┬──> │└─> integer ─────┘ ├─>
A
S
C ──┤ │ │ └─>
D
E
S
C ─┘ │ └──────────── , <───────────────┘
Additional information available:
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.
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.
You cannot refer to read-only cursors in UPDATE or DELETE statements.
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
select expr
select-expr = 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 ─┘ └─────── , <─────┘
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 ──────┬───────┘ └───>
T
R
A
N
S
A
C
T
I
O
N ─┘
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 Informationcol 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.
col definition
col-definition =
──> column-name ─┬─> data-type ───┬┬┬──────────>─────────────┬┬─>
└─> domain-name ─┘│├─> col-constraint ──────┤│
│└─> sql-and-dtr-clause ──┘│
└───────────<──────────────┘
col-constraint =
─┬──────>────────────────────────┬─┬───────────────────────────────┬─>
├─>
N
O
T
N
U
L
L ───────────────────┤ └─>
D
I
A
G
N
O
S
T
I
C constraint-name ─┘
├─>
N
O
T
N
U
L
L
U
N
I
Q
U
E ────────────┤
└─>
C
H
E
C
K (predicate) ──────────┘
The column definition specifies a data type and optional
column-constraints and SQL and DATATRIEVE formatting support clauses
for the column specified by the column name.
Additional information available:
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 = ─┬─>
U
N
I
Q
U
E (─┬─> column-name ─┬─> ) ─┬─┐ │ └───── , <───────┘ │ │ └─>
C
H
E
C
K (predicate) ───────────────┘ │ ┌────────────────────────────────────┘ └─┬───────────────────────────────┬─> └─>
D
I
A
G
N
O
S
T
I
C constraint-name ─┘
Additional information available:
More Information
A table-constraint is a constraint definition that applies to the
whole table. There are two types of table constraints, UNIQUE and
CHECK and an optional DIAGNOSTIC constraint name.
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.
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 optional DIAGNOSTIC constraint-name specifies a name for a column
or table 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
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 ──┘ └─>
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.