Declaring temporary tables
To define temporary tables from within your applications, use the DECLARE GLOBAL TEMPORARY TABLE statement.
About this task
- User-defined type columns
- LONG VARCHAR columns
- XML columns for created global temporary tables
Example
DECLARE GLOBAL TEMPORARY TABLE temptbl
LIKE empltabl
ON COMMIT DELETE ROWS
NOT LOGGED
IN usr_tbspThis statement
defines a temporary table called temptbl. This table
is defined with columns that have exactly the same name and description
as the columns of the empltabl. The implicit definition
only includes the column name, data type, nullability characteristic,
and column default value attributes. All other column attributes including
unique constraints, foreign key constraints, triggers, and indexes
are not defined. With ON COMMIT DELETE ROWS (any DELETE ROWS option),
the database manager always deletes rows whether there's a cursor
with a HOLD open on the table or not. The database manager optimizes
a NOT LOGGED delete by implementing an internal TRUNCATE, if no WITH
HOLD cursors are open, otherwise, the database manager deletes the
rows one at a time.
The table is dropped implicitly when the application disconnects from the database. For more information, see the DECLARE GLOBAL TEMPORARY TABLE statement.