18.7. TEMPORARY TABLE Declarations

The temporary table can be used with SQL/PSM code to hold intermediate results rather than requerying or recalculating them over and over. The syntax for creating a TEMPORARY TABLE is:

CREATE [GLOBAL | LOCAL] TEMP[ORARY] TABLE <table name>
 (<table element list>)
ON COMMIT [PRESERVE | DELETE] ROWS;

This is just like the usual CREATE TABLE statement, with the addition of two pieces of syntax. The <table element>s can be column declarations, constraints, or declarative referential integrity clauses, just as if this were a base table. The differences come from the additional clauses.

The GLOBAL option in the TEMPORARY means that one copy of the table is available to all the modules of the application program in ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.