Table partitioning in Oracle Database

1,027 views

Published on

ORACLE TABLE PARTITIONING

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,027
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
4
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Table partitioning in Oracle Database

  1. 1. RANGE PARTITIONINGCREATE TABLE abc ( prod_id NUMBER(6) , cust_id NUMBER, time_id DATE , channel_id CHAR(1) , promo_id NUMBER(6) ,quantity_sold NUMBER(3) , amount_sold NUMBER(10,2) )PARTITION BY RANGE (time_id) ( PARTITION sales_q1_2006VALUES LESS THAN (TO_DATE(01-APR-2006,dd-MON-yyyy))TABLESPACE tbs1 , PARTITION sales_q2_2006 VALUES LESSTHAN (TO_DATE(01-JUL-2006,dd-MON-yyyy)) TABLESPACEtbs2 ,PARTITION sales_q3_2006 VALUES LESS THAN(TO_DATE(01-OCT-2006,dd-MON-yyyy)) TABLESPACE tbs3,PARTITION sales_q4_2006 VALUES LESS THAN(TO_DATE(01-JAN-2007,dd-MON-yyyy)) TABLESPACE tbs4);
  2. 2. LIST PARTITIONINGCREATE TABLE sales_list (salesman_idNUMBER(5),salesman_name VARCHAR2(30), sales_stateVARCHAR2(20),sales_amount NUMBER(10), sales_date DATE)PARTITION BY LIST(sales_state) ( PARTITIONsales_west VALUES(California, Hawaii),PARTITION sales_east VALUES (New York,Virginia, Florida),PARTITION sales_central VALUES(Texas,Illinois)PARTITION sales_other VALUES(DEFAULT) );
  3. 3. HASH PARTITIONINGCREATE TABLE dept (deptno NUMBER, deptnameVARCHAR(32))STORAGE (INITIAL 10K) PARTITION BYHASH(deptno)(PARTITION p1 TABLESPACE ts1, PARTITION p2TABLESPACE ts2,PARTITION p3 TABLESPACE ts1, PARTITION p4TABLESPACE ts3);
  4. 4. RANGE-HASH PARTITIONINGCREATE TABLE sales ( prod_id NUMBER(6) , cust_idNUMBER , time_id DATE ,channel_id CHAR(1) , promo_id NUMBER(6) ,quantity_sold NUMBER(3) ,amount_sold NUMBER(10,2) ) PARTITION BY RANGE(time_id)SUBPARTITION BY HASH (cust_id) SUBPARTITIONS 8 STORE IN(ts1, ts2, ts3, ts4)( PARTITION sales_q1_2006 VALUES LESS THAN(TO_DATE(01-APR-2006,dd-MON-yyyy)), PARTITION sales_q2_2006 VALUES LESS THAN(TO_DATE(01-JUL-2006,dd-MON-yyyy)) ,PARTITION sales_q3_2006 VALUES LESS THAN(TO_DATE(01-OCT-2006,dd-MON-yyyy)) ,PARTITION sales_q4_2006 VALUES LESS THAN (TO_DATE(01-JAN-2007,dd-MON-yyyy)) );
  5. 5. RANGE-LIST PARTITIONINGCREATE TABLE quarterly_regional_sales (deptno number,item_no varchar2(20),txn_date date, txn_amount number, state varchar2(2))TABLESPACE ts4 PARTITION BY RANGE (txn_date)SUBPARTITION BY LIST(state) (PARTITION q1_1999 VALUES LESS THAN (TO_DATE(1-APR-1999,DD-MON-YYYY))(SUBPARTITION q1_1999_northwest VALUES (OR, WA),SUBPARTITION q1_1999_southwest VALUES(AZ, UT, NM), SUBPARTITION q1_1999_northeast VALUES(NY, VM, NJ),SUBPARTITION q1_1999_southeast VALUES (FL, GA),SUBPARTITION q1_1999_northcentral VALUES (SD, WI),SUBPARTITION q1_1999_southcentral VALUES (OK, TX) ),
  6. 6. PARTITION q2_1999 VALUES LESS THAN (TO_DATE(1-JUL-1999,DD-MON-YYYY))(SUBPARTITION q2_1999_northwest VALUES(OR, WA),SUBPARTITION q2_1999_southwest VALUES(AZ, UT, NM),SUBPARTITION q2_1999_northeast VALUES(NY, VM, NJ),SUBPARTITION q2_1999_southeast VALUES(FL, GA),SUBPARTITION q2_1999_northcentralVALUES (SD, WI),SUBPARTITION q2_1999_southcentralVALUES (OK, TX) ),
  7. 7. PARTITION q3_1999 VALUES LESS THAN (TO_DATE(1-OCT-1999,DD-MON-YYYY))(SUBPARTITION q3_1999_northwest VALUES (OR,WA),SUBPARTITION q3_1999_southwest VALUES (AZ,UT, NM),SUBPARTITION q3_1999_northeast VALUES (NY,VM, NJ),SUBPARTITION q3_1999_southeast VALUES (FL,GA),SUBPARTITION q3_1999_northcentral VALUES(SD, WI),SUBPARTITION q3_1999_southcentral VALUES(OK, TX) ),
  8. 8. PARTITION q4_1999 VALUES LESS THAN (TO_DATE(1-JAN-2000,DD-MON-YYYY))(SUBPARTITION q4_1999_northwest VALUES (OR,WA),SUBPARTITION q4_1999_southwest VALUES (AZ,UT, NM),SUBPARTITION q4_1999_northeast VALUES (NY,VM, NJ),SUBPARTITION q4_1999_southeast VALUES (FL,GA),SUBPARTITION q4_1999_northcentral VALUES(SD, WI),SUBPARTITION q4_1999_southcentral VALUES(OK, TX) ) );
  9. 9. INDEX ORGANIZED TABLECREATE TABLE country( country_id CHAR(2)CONSTRAINT country_id_nn NOT NULL,country_name VARCHAR2(40),currency_name VARCHAR2(25),currency_symbol VARCHAR2(3),map BLOB,flag BLOB,CONSTRAINT country_c_id_pkPRIMARY KEY (country_id))ORGANIZATION INDEXTABLESPACE indxPCTTHRESHOLD 20OVERFLOW TABLESPACE users;
  10. 10. CLUSTURED TABLES# Create the clustercreate cluster emp_dept( deptno number(3)) tablespace users;# Create the two tables that are partof the clustercreate table dept ( deptno number (3)primary key) cluster emp_dept (deptno);create table emp ( empno number (5)primary key, ename varchar2(15), deptnonumber (3) references dept) clusteremp_dept (deptno);

×