DB2 temporary table

Source: Internet
Author: User

---- 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.