Oracle 分区表常用SQL语句 (转载)
2009-03-10 15:38
901 查看
*********
为分区表建立一个单独的表空间
*********/create tablespace ts_partition datafile '/home/oracle/oradata/esales/partition.dbf' size 10M
extent management local uniform size 2M;
/*********
建立分区表
*********/create table bigtable
(
sale_date date,
product_id number,
sale_count number,
charge number,
sales_id number
)
tablespace ts_partition
pctfree 5
pctused 80
initrans 1
maxtrans 255
parallel(degree 2)
storage
(
initial 2M
next 2M
minextents 1
maxextents unlimited
pctincrease 0
)
partition by range(sale_date)
(
partition sale_date_20020101 values less than (to_date('20020102','yyyymmdd')),
partition sale_date_20020102 values less than (to_date('20020103','yyyymmdd'))
);
/*********
建立分区索引
*********/create index create index idx_bigtable_product_id on bigtable(product_id) parallel 2 local
tablespace users on bigtable(product_id) parallel 2 local tablespace users;
/*********
增加分区
*********/alter table bigtable add partition sale_date_20020103
values less than (to_date('20020104','yyyymmdd'));
/*********
截断分区
*********/alter table bigtable truncate partition sale_date_20020103;
/*********
丢弃分区
*********/alter table bigtable drop partition sale_date_20020103;
/*********
交换分区
如果分区表里含有 LOCAL 的索引,此分区的索引将处于不可用状态,需要重建:
alter index idx_bigtable_product_id rebuild partition sale_date_20020102 tablespace users;
如果被交换表和分区表的索引结构相同,可以用 including indexes 连同索引一起交换,不必重建索引。
*********/create table bigtable_temp tablespace users as select * from bigtable where 1=2;
insert into bigtable_temp values (to_date('20020102','yyyymmdd'),1,10,1,10);
commit;
alter table bigtable exchange partition sale_date_20020102 with table bigtable_temp;
/*********
移动分区
*********/alter table bigtable move partition sale_date_20020102 tablespace user2;
/*********
修改分区
*********/alter table bigtable modify partition
sale_date_20020102 storage(pctincrease 10);
/*********
重命名分区
*********/alter table bigtable rename partition
sale_date_20020102 to sale_date_20020103;
/*********
分割分区
*********/alter table bigtable add partition sale_date_20020104
values less than (to_date('20020105','yyyymmdd'));
alter table bigtable split partition sale_date_20020104
at (to_date('20020104','yyyymmdd'))
into (partition sale_date_20020103,partition sale_date_20040104);
/*********
分区表数据的逻辑备份
exp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104)
分区表数据的逻辑恢复
imp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104) ignore=y
*********/
为分区表建立一个单独的表空间
*********/create tablespace ts_partition datafile '/home/oracle/oradata/esales/partition.dbf' size 10M
extent management local uniform size 2M;
/*********
建立分区表
*********/create table bigtable
(
sale_date date,
product_id number,
sale_count number,
charge number,
sales_id number
)
tablespace ts_partition
pctfree 5
pctused 80
initrans 1
maxtrans 255
parallel(degree 2)
storage
(
initial 2M
next 2M
minextents 1
maxextents unlimited
pctincrease 0
)
partition by range(sale_date)
(
partition sale_date_20020101 values less than (to_date('20020102','yyyymmdd')),
partition sale_date_20020102 values less than (to_date('20020103','yyyymmdd'))
);
/*********
建立分区索引
*********/create index create index idx_bigtable_product_id on bigtable(product_id) parallel 2 local
tablespace users on bigtable(product_id) parallel 2 local tablespace users;
/*********
增加分区
*********/alter table bigtable add partition sale_date_20020103
values less than (to_date('20020104','yyyymmdd'));
/*********
截断分区
*********/alter table bigtable truncate partition sale_date_20020103;
/*********
丢弃分区
*********/alter table bigtable drop partition sale_date_20020103;
/*********
交换分区
如果分区表里含有 LOCAL 的索引,此分区的索引将处于不可用状态,需要重建:
alter index idx_bigtable_product_id rebuild partition sale_date_20020102 tablespace users;
如果被交换表和分区表的索引结构相同,可以用 including indexes 连同索引一起交换,不必重建索引。
*********/create table bigtable_temp tablespace users as select * from bigtable where 1=2;
insert into bigtable_temp values (to_date('20020102','yyyymmdd'),1,10,1,10);
commit;
alter table bigtable exchange partition sale_date_20020102 with table bigtable_temp;
/*********
移动分区
*********/alter table bigtable move partition sale_date_20020102 tablespace user2;
/*********
修改分区
*********/alter table bigtable modify partition
sale_date_20020102 storage(pctincrease 10);
/*********
重命名分区
*********/alter table bigtable rename partition
sale_date_20020102 to sale_date_20020103;
/*********
分割分区
*********/alter table bigtable add partition sale_date_20020104
values less than (to_date('20020105','yyyymmdd'));
alter table bigtable split partition sale_date_20020104
at (to_date('20020104','yyyymmdd'))
into (partition sale_date_20020103,partition sale_date_20040104);
/*********
分区表数据的逻辑备份
exp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104)
分区表数据的逻辑恢复
imp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104) ignore=y
*********/
相关文章推荐
- Oracle 分区表常用SQL语句 (转载)
- 比较常用的Oracle的SQL语句语法
- oracle常用sql查询语句部分集合(图文)
- Oracle常用sql语句(二)之组函数、多表查询
- Oracle常用sql语句(三)之子查询
- Oracle常用Sql语句进行总结
- oracle维护常用SQL语句(查看系统表和视图)
- 【转载】oracle性能检测sql语句
- oracle 查询最近执行过的 SQL语句(转载)
- ORACLE常用SQL优化hint语句
- oracle常用sql语句语法
- [转载]两个常用的SQL语句
- [转载]Oracle中SQL语句的几种用法
- [转载]SQL Server 数据库管理常用的SQL和T-SQL语句[备份贴]
- oracle下常用sql语句
- Oracle常用sql语句(查询数据库中锁表、查询数据库表字段总数)
- Oracle维护常用SQL语句
- 常用SQL语句1(Oracle)
- Oracle SQL常用语句
- Oracle常用sql语句初体验select成功=努力+方法。