Table

Partition table

위니쓰 2012. 2. 25. 23:33

○ 관련 dictionary 및 view 정보

dba_tab_partitions

dba_part_tables

dba_ind_partitions

○ Partiton Table 생성

SQL> CREATE TABLE DEPT

(deptno number not null,

dname varchar2(10) not null,

loc varchar2(14))

PARTITION BY RANGE(deptno)

(PARTITION part1 VALUES LESS THAN(30).

PARTITION part2 VALUES LESS THAN(MAXVALUE));

○ LOCAL PREFIX INDEX 생성

- index 의 파티션이 Table의 파티션과 동일하게 생성된다.

SQL> CREATE INDEX deptloc1_idx dept(deptno) LOCAL

○ LOCAL NON-PREFIX INDEX 생성

SQL> CREATE INDEX deptloc2_idx dept(loc) LOCAL;

○ GLOBAL PREFIX INDEX 생성

- index 의 파티션이 Table의 파티션과는 다르게 생성된ㄷ.

CREATE INDEX dept_idx ON(dname)

GLOBAL PARTITION BY RANGE(dname)

(PARTITION p1 VALUES LESS THAN('N'),

PARTITION P2 VALUES LESS THAN(MAXVALUE) );

○ Partition 추가

SQL> alter table dept

add partition p3 values less than('20101010') tablespace TBS01;

○ Partition 삭제

SQL> alter table dept

drop partiton p3 ;

○ Partition 나누기 ( Split)

SQL> alter table dept

split partition p3

at('20100229')

into ( partition p3_1 tablespace TBS01,

partition p3_2 tablespace TBS02);

==> 20100229 값 이하는 P3_1 파티션에, 20100229 값 이상(20100301)은 P3_2 에 입력된다.

○ Partition Name 변경

SQL> alter table part_table rename partition part_01 to part_02;

○ Partition의 Tablespace 옮기는 방법

SQL> alter table part_table move partition tablespace TBS01 nologging;

○ Partition Truncate

SQL> alter table part_table truncate partition part_02;

○ Partition 물리적 속성 변경

SQL> alter table part_table storage( next 10m ); ==> 모든 파티션의 속성값이 변경됨

SQL> alter table part_table modify partition part_02 storage( initial 100m );

==> 해당 파티션의 속성값만 변경됨

○ Partition Exchage

- 파티션 테이블을 일반 테이블로 변경하거나,

일반 테이블을 파티션 테이블로 변경시킬 때 사용가능하다.

SQL> CREATE TABLE p_emp

(sal number(7,2))

PARTITION BY RANGE(sal)

(PARTITION emp_p1) values less than(2000),

partition emp_p2 values less than(4000)) ;

SQL> create table dummy_y

as

select sal from emp

where sal <2000;

SQL> create table dummy_z

as

select sal from emp

where sal between 2000 and 3999;

SQL> alter table p_emp exchange Partition emp_p1 with table dummy_y;

SQL> alter table p_emp exchange Partition emp_p2 with table dummy_z;