4. Managing Tables and Views : Synonyms, Temporary Tables, and Comments : Temporary Tables : Examples of Working with Temporary Tables
 
Share this page                  
Examples of Working with Temporary Tables
To create two temporary tables, names and employees, for the current session, issue the following statements:
DECLARE GLOBAL TEMPORARY TABLE SESSION.names
  (name VARCHAR(20), empno VARCHAR(5))
  ON COMMIT PRESERVE ROWS 
  WITH NORECOVERY;
DECLARE GLOBAL TEMPORARY TABLE SESSION.employees AS
  SELECT name, empno FROM employees
  ON COMMIT PRESERVE ROWS
  WITH NORECOVERY;
Note:  The “session.” qualifier in the example is optional. If omitted, the name of the temporary table cannot be the same as any permanent table names.
The names of temporary tables must be unique only in a session.
For more information on working with temporary tables, see the descriptions for DECLARE GLOBAL TEMPORARY TABLE and DROP statements.