2008年9月11日 星期四

Table Partitioning (II) using DB2 9


/*
 關於 HIGHVALUE 的值看起來跟 LOWVALUE overlap 的問題
*/

/* 首先,先恢復原狀 */

create table day_list
(
   dt date
) partition by range(dt)
(starting '2008-01-01' ending '2008-12-31' every 3 months)

DB20000I The SQL command completed successfully.


/*
 開啟 db2cc
 原來 SYSIBM.SYSDATAPARTITIONS 還有一個欄位 HIGHINCLUSIVE
 N 是不包含 HIGHVALUE 的值,Y 則是要包含。
 所以除了 PART3 是有包含 '2008-12-31' 之外,其它都是設成 N
*/



/* 應當是與建立時下的語法有關 */

partition by range(dt)
(starting '2008-01-01' ending '2008-12-31' every 3 months)

/* 將 part0 detach */

alter table day_list detach partition part0 into tab_reuse0
DB20000I The SQL command completed successfully.

/* 將 part0 attach 回來 */

alter table day_list attach partition part0 starting '2008-01-01' ending '2008-03-31' from tab_reuse0
SQL3601W The statement caused one or more tables to automatically be placed
in the Set Integrity Pending state. SQLSTATE=01586

/* 檢查完整性 */

set integrity for day_list immediate checked
DB20000I The SQL command completed successfully.


/*
 db2cc 裡 SYSIBM.SYSDATAPARTITIONS 欄位 HIGHINCLUSIVE 值在 PART0 已經改為 Y,
 且值即是所給定的 ending 值 '2008-03-31'
*/





/* 
 另外,順便用 db2cc 看一下有哪些 tablespaces
 ※ 要特別注意 IBMDB2SAMPLEREL 這個 tablespace
*/




/*
 選擇 DAY_LIST 這個 TABLE (它的 Table space 是 Partitioned Table)
 點右鍵時多了一個選項 Open Data Partitions
*/




/* 
 選擇Open Data Partitions 之後出現 Data Partition 的內容 
 Partitions 的 Tablespace 就是放在 IBMDB2SAMPLEREL
 另外,Starting Value 就是 LOWVALUE、
 Ending Value 就是 HIGHVALUE
 Ending Value Inclusive 就是 HIGHINCLUSIVE 的內容
*/