---- Start
Temporary tables are usually used to define temporary sets. However, when most temporary sets are required, we do not need to define temporary tables. When we use only one temporary set in an SQL statement, we can useNested table expressionsTo define a temporary set. When we need to use the same temporary set multiple times in an SQL statement, we can useCommon table expressionsThe temporary table must be defined only when the same temporary set is used in multiple SQL statements in a unit of work.
You can define a temporary table in the following three ways:
Method 1: <br/> declare global temporary table session. EMP <br/> (<br/> name varchar (10), --- name <br/> dept smallint, --- Department <br/> salary Dec (7,2) --- salary <br/>) <br/> On commit Delete rows; </P> <p> Method 2: <br/> declare global temporary table session. EMP <br/> like staff including column defaults <br/> with replace <br/> On commit preserve rows; </P> <p> method 3: <br/> declare global temporary table session. EMP as <br/> (<br/> select * from staff where <condition> <br/>) <br/> definition only <br/> with replace;
After a temporary table is defined, we can use a temporary table just like a normal table. A temporary table is only valid for users who define it. Different users can define temporary tables with the same name at the same time. They do not affect each other. The life cycle of a temporary table is session. When the session is closed, the temporary table is automatically deleted. This is why the mode name of the temporary table can only be session. In addition, we can define indexes for temporary tables. For more details, see DB2 Information Center.
---- For more information, see:DB2 SQL
----Statement: indicate the source for reprinting.
---- Last updated on 2010.1.27
---- Written by shangbo on 2010.1.27
---- End