DB2--DB2 Creation of temporary tables

Source: Internet
Author: User
Tags create index

DB2 supports session temp table. The table can only exist in a session or in a transaction context and is not visible to other users. DB2 V8 adds support for indexing of temporary tables, which is useful for increasing query speed.

The following example illustrates the use of the session temp table:

1. Before creating a session temp table, you must create a temporary table space
Create user temporary tablespace test
PageSize 4 K Managed by system
using (' [curdir]\temp ');

2. Define the session temp table, which copies the table structure of transactions, on commit preserve rows to specify that even if the transaction is submitted, the data in the T1 temp table still exists,
The T1 table disappears only when the session is terminated.

If you do not add on commit preserve rows, the data in the temporary table will be automatically deleted when the insert temporary tables are submitted.

Declare global temporary table T1
Like transactions
On commit preserve rows not logged in test;

3. Insert the records of the transaction table into the T1 temporary table.
INSERT INTO SESSION.T1
SELECT * FROM Transactions

4. Select a record from the T1 table, and notice how fast this statement executes.
SELECT * FROM session. T1
Where store= ' Rockwood ';

5. Create an index on the T1 table, DB2 V8 allows you to create an index on a temporary table to increase the query speed on the staging table.
Create INDEX Session.t1index on SESSION.T1 (store);

6. If you execute the same SELECT statement again, you can see that the query speed has improved.
SELECT * FROM session. T1
Where store= ' Rockwood ';

7. In DB2 9, you do not have to create a temporary table space yourself, and a temporary table space Systoolstmpspace is created automatically when you create the staging tables.

DB2--DB2 Creation of temporary tables

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.