Global Temporary Tables

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Temporary tables generally contain all of the features that ordinary tables have like triggers, join cardinality, information about rows and block etc. the main difference is that the temporary tables can't have foreign keys related to other tables.

Syntax

  1. CREATE GLOBAL TEMPORARY TABLE table_name  
  2. ( column1 datatype [ NULL | NOT NULL ],  
  3.   column2 datatype [ NULL | NOT NULL ],  
  4.   ...  
  5.   column_n datatype [ NULL | NOT NULL ]  
  6. );  

Parameters

table_name: The parameter table_name specifies the global temporary table that you want to create.

column1, column2, ... column_ n: It specifies the column that you want create in the global temporary table. Every column must have a datatype and should be defined as NULL or NOTNULL. If the value is left blank, it is by default treated as NULL.

Example

The following example specifies how to create a global temporary table

  1. CREATE GLOBAL TEMPORARY TABLE students  
  2. ( student_id numeric(10) NOT NULL,  
  3.   student_name varchar2(50) NOT NULL,  
  4.   student_address varchar2(50)  
  5. );  
 This will create a global temporary table called students