Creating temporary tables

Temporary tables are useful when you need to sort or query intermediate result tables that contain large numbers of rows and identify a small subset of rows to store permanently. The two types of temporary tables are created temporary tables and declared temporary tables.

About this task

Use a created temporary table when you need a permanent, sharable description of a table, and you need to store data only for the life of an application process. Use a declared temporary table when you need to store data for the life of an application process, but you don't need a permanent, sharable description of the table.

Procedure

To create a temporary table:

  1. Determine the type of temporary table that you want to create.
  2. Issue the appropriate SQL statement for the type of temporary table that you want to create:
    • To define a created temporary table, issue the CREATE GLOBAL TEMPORARY TABLE statement.
    • To define a declared temporary table, issue the DECLARE GLOBAL TEMPORARY TABLE statement.