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

You can use temporary tables to sort large volumes of data and to query that data. Then, when you have identified the smaller number of rows that you want to store permanently, you can store them in a base table.

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.