[DB2 database creates partition table]

Create tablespace

CREATE TABLESPACE DMS01

 

CREATE TABLESPACE dms02

 

CREATE TABLESPACE dms03

 

create table

CREATE TABLE artists

(

artno SMALLINT NOT NULL PRIMARY KEY,

name VARCHAR(50),

picture BLOB(2M) NOT LOGGED COMPACT

)

IN dms01

INDEX IN dms02

LONG  IN dms03

 

CREATE INDEX idx_name ON artists (name)

 

Use of partition table

Define interval

CREATE TABLE sales(sale_date DATE, customer INT) 

PARTITION BY RANGE(sale_date)

(    

STARTING '1/1/2000'  ENDING '3/31/2000',    

STARTING '4/1/2000'  ENDING '6/30/2000',

STARTING '7/1/2000'  ENDING '9/30/2000',    

STARTING '10/1/2000' ENDING '12/31/2004'   

);

 

 

 

Use MINVALUE and MAXVALUE to specify open intervals

CREATE TABLE sales11(sale_date DATE, customer INT)

  PARTITION BY RANGE(sale_date)    

(

STARTING MINVALUE    ENDING '12/31/1999',    

STARTING '1/1/2000'  ENDING '3/31/2000',   

STARTING '4/1/2000'  ENDING '6/30/2000',    

STARTING '7/1/2000'  ENDING '9/30/2000',    

STARTING '10/1/2000' ENDING '12/31/2004' 

);

 

 

Use the EXCLUSIVE keyword to specify whether to include, and finally '12/31/2004' is not included in the range

CREATE TABLE sales(sale_date DATE, customer INT, …)

  PARTITION BY RANGE(sale_date)    

(

STARTING MINVALUE    ENDING '1/1/2000'  EXCLUSIVE,    

STARTING '1/1/2000'  ENDING '4/1/2000'  EXCLUSIVE,    

STARTING '4/1/2000'  ENDING '7/1/2000'  EXCLUSIVE,

STARTING '7/1/2000'  ENDING '10/1/2000' EXCLUSIVE,

STARTING '10/1/2000' ENDING '12/31/2004'   

); 

 

The ALTER TABLE statement can perform the following operations on existing tables:

Increase

Add one or more columns to the table

add or delete

primary key

Unique index , reference or check constraint definitions or check constraint definitions

drop table constraint

Partition KEY (DPF)

change column

delete column

Change column type

Change column NULL type

Change the length of VARCHAR

change table type

Change the Change table attribute

DATA CAPTURE, PCTFREE, LOCK SIZE 或APPEND MODE.

Set table property NOT LOGGED INITIALLY

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326994387&siteId=291194637