Saturday 30 March 2013

Temp Tables- Part 1 - Introduction



There are 3 types of temp tables:
  1. Global temp tables
  1. Volatile tables
  1. Derived tables


What are the disadvantages of using permanent tables for temporary purposes:
  1. We need to have separate steps to create and populate tables
  1. It takes perm space to create these tables.
  1. We need to drop the table explicitly after we are done using the tables.
  1. Data dictionary access is needed for creating and dropping the tables.



Derived Tables
Volatile temp tables
Global temporary tables
    1. These tables are local to the query. The tables exists for the duration of the query
    1. Makes use of spool space.
    1. No data dictionary involvement needed
    1. Tables are created using SQL incorporated within the query.
    1. These tables are local to the session and not just the query. The table is discarded at the end of the session.
    1. Makes use of spool space.
    1. No Data dictionary involvement needed
    1. Table must be explicitly created using the CREATE VOLATILE TABLE syntax.
    1. This table is also local to the session and not just the query. The Table instance is discarded at the end of the session.

    The way Global temp tables are different from the volatile table is that global table has a definition in the Data dictionary . This data definition can be shared by multiple users.

    1. Makes use of temp space.
    1. Data dictionary involvement necessary as the definition is stored in data dictionary.
    1. The table definition in the data dictionary is created using the CREATE GLOBAL TEMPORARY TABLE syntax. The instances of the tables are materialized using many other ways explained later.


No comments:

Post a Comment