Hash Partitioning Definition

Description

You can define a hash partition by using the PARTITION BY HASH clause.

Syntax

CREATE TABLE (

...

)

( PATITION BY HASH ( <partition_expression> )

 PATITIONS ( <number_of_partitions> )

)

Example 1

The following example shows how to create the nation2 table with country codes and country names, and define 4 hash partitions based on code values. Only the number of partitions, not the name, is defined in hash partitioning; names such as p0 and p1 are assigned automatically.

CREATE TABLE nation2

( code CHAR(3),

name VARCHAR(50) )

PARTITION BY HASH ( code) PARTITIONS 4;

Example 2

The following example shows how to insert data to the hash partition created in the example 1. When a value is inserted into a hash partition, the partition to store the data is determined by the hash value of the partition key. If the partition key value is NULL, the data is stored in the first partition.

INSERT INTO nation2 VALUES ('KOR','Korea');

INSERT INTO nation2 VALUES ('USA','USA United States of America');

INSERT INTO nation2 VALUES ('FRA','France');

INSERT INTO nation2 VALUES ('DEN','Denmark');

INSERT INTO nation2 VALUES ('CHN','China');

INSERT INTO nation2 VALUES (NULL,'AAA');

Caution

The maximum number of partitions cannot exceed 1024.