分割槽表建立與截斷

2021-07-09 05:21:21 字數 2363 閱讀 9245

建立:

create table event_table

( name varchar2(100 byte) not null,

occur_time date not null,

msecond number(10) not null,

content varchar2(160 byte)

)nocompress

tablespace history_tablespaces

result_cache (mode default)

pctused 40

pctfree 1

initrans 1

maxtrans 255

storage (

initial 64m

next 64m

maxsize unlimited

minextents 1

maxextents unlimited

pctincrease 0

buffer_pool keep

flash_cache default

cell_flash_cache default

)nologging

partition by range (occur_time)

interval( numtoyminterval(1,'month'))

( partition event_table_1 values less than (to_date(' 2001-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss', 'nls_calendar=gregorian'))

nologging

nocompress

tablespace history_tablespaces

pctused 40

pctfree 10

initrans 1

maxtrans 255

storage (

initial 1280k

next 1280k

maxsize unlimited

minextents 1

maxextents unlimited

pctincrease 0

freelists 1

freelist groups 1

buffer_pool keep

flash_cache default

cell_flash_cache default

))cache

parallel ( degree default instances default )

monitoring;

create index pk_event_table on event_table

(occur_time)

nologging

local

tablespace history_tablespaces_index

pctfree 1

initrans 2

maxtrans 255

storage (

initial 64m

next 64m

maxsize unlimited

minextents 1

maxextents unlimited

pctincrease 0

freelists 1

freelist groups 1

buffer_pool keep

flash_cache default

cell_flash_cache default

)parallel ( degree default instances default );

需要注意的兩點:

1. numtoyminterval後面只能跟年或者月,沒有「周」之類的選項。

2. 索引建立必須加local,否則索引仍使用全域性分割槽,查詢效率得不到提公升。

截斷分割槽:

alter table truncate partition ;

Oracle 建立分割槽表

建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...

hive 建立分割槽表

必須在表定義時建立partition a 單分割槽建表語句 create table day table id int,content string partitioned by dt string 單分割槽表,按天分割槽,在表結構中存在id,content,dt三列。以dt為資料夾區分 b 雙分割...

Oracle 建立分割槽表

建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...