Personal tools
You are here: Home DB2 DB2 UDB v9 How to create partitioned tables on DB2 v9
Navigation
Log in


Forgot your password?
 
Document Actions

How to create partitioned tables on DB2 v9

creating partitioned tables on DB2 v9 to get a lot of benefits

To create a partitioned table from the command line, issue the CREATE TABLE statement:

 

CREATE TABLE <NAME> (<column_name>  <data_type>  <null_attribute>) IN
   <table space list> PARTITION BY RANGE (<column expression>) 
    STARTING FROM <constant> ENDING <constant> EVERY <constant>

 

 

For example, the following statement creates a table where rows with fired ≥  2009-01-01 and fire ≤ 2009-01-31 are in PART0 (the first data partition), rows with 2009-01-02 ≤ fired ≤  2009-02-29 are in PART1 (the second data partition), up to 2010-12-01 ≤ fired ≤ 2010-12-31 are in PART24 (the last data partition).

 

CREATE TABLE tableX(COD INT, fired date) in tspace1, tspace2 
    PARTITION BY RANGE (fired) (STARTING FROM ('2009-01-01') 
    ENDING AT (2010-12-31) EVERY 1 MONTH)

 

Example 2:

If you wanted to create a table named DEPARTMENTS that is partitioned such that rows with numerical values that fall in the range of 0 to 9 are stored in one partition that resides in one table space, rows with numerical values that fall in the range of 10 to 19 are stored in another partition that resides in another table space, and so on, you could do so by executing a CREATE TABLE SQL statement that looks something like this:

 

CREATE TABLE departments
(dept_no INT
desc CHAR(3))
PARTITION BY (dept_no NULLS FIRST)
(STARTING 0 ENDING 9 IN tbsp0,
STARTING 10 ENDING 19 IN tbsp1,
STARTING 20 ENDING 29 IN tbsp2,
STARTING 30 ENDING 39 IN tbsp3)

 

A table with the same partitioning scheme could also be created by executing a CREATE TABLE SQL statement that looks something like this:

CREATE TABLE departments
(dept_no INT
desc CHAR(3))
IN tbsp0, tbsp1, tbsp2, tbsp3
PARTITION BY (dept_no NULLS FIRST)
(STARTING FROM(0) ENDING(39) EVERY(10))
Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls