Link to home
Start Free TrialLog in
Avatar of toooki
toooki

asked on

Creating Oracle partitioned table

I need to create a partition table that will have a Hash partition on batch_id .. Have a question..

Here is the table creation command that I plan to use:

CREATE TABLE mytab1
   (BATCH_ID NUMBER DEFAULT -1,
     ID number NUMBER(*,0),
     Field1 varchar2(10)
)
   PARTITION BY HASH(BATCH_ID)
STORE IN (MyTablespaceName1);


Is this a correct command to create the partitioned  table on BATCH_ID? The table gets created as above.

Does it create multiple partitions for separate group of  BATCH_ID values when they are inserted into the table?
Thank you...
ASKER CERTIFIED SOLUTION
Avatar of Christoffer Swanström
Christoffer Swanström
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
toooki

ASKER

Thanks a lot. Ok if I use PARTITIONS 64

I wanted to know if the table has 100 different BATCH_ID values, does it still create only 64 partitions at the max? so there are multiple rows in the table with same BATCH_ID values that reside in the same partition?

Thank you.
Yes, it will only create the number of partitions you define. Typically you will have lots of distinct key values for each partition.
You will have as many partitions as distinct value of batch_id
Bajwa: that's not correct. If you do not specify the number of partitions, you will get one partition only, no matter how many distinct values you have for the the column that the table is partitioned on. If you specify the number of partitions, you will get exactly the number of partitions you specified, no more nor less.

You can verify the number of partitions you get when you do not specify the PARTITIONS clause by running the following:

DROP TABLE swc_tst;
CREATE TABLE swc_tst (
col1 NUMBER
)
PARTITION BY HASH(col1)
;

SELECT * FROM all_tab_partitions WHERE table_name = 'SWC_TST';

INSERT INTO SWC_TST VALUES(1);
INSERT INTO SWC_TST VALUES(2);
INSERT INTO SWC_TST VALUES(3);
INSERT INTO SWC_TST VALUES(4);
INSERT INTO SWC_TST VALUES(5);
COMMIT;

SELECT * FROM all_tab_partitions WHERE table_name = 'SWC_TST';

You still have only one partition after inserting multiple values...
Avatar of toooki

ASKER

Thanks a lot!! I now understand.