转移表空间步骤

本文详细介绍了在Oracle数据库中转移表空间的步骤,包括ALTER TABLE MOVE命令用于转移表和分区,以及重建索引的方法。此外,还涵盖了如何更改用户默认表空间,处理丢失数据文件的情况,以及分区表的各种操作,如添加、删除、分裂和合并分区。同时,文章讨论了本地和全局索引的创建和管理,为数据库管理员提供了全面的操作指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转移表空间步骤
一、转移表空间
ALTER TABLE tab_name MOVE TABLESPACE tabspace_name;

分区表

ALTER TABLE table_name MOVE PARTITION  para_name TABLESPACE tablespace_name;
批量生成语句:
select 'ALTER TABLE '||TABLE_NAME||' MOVE TABLESPACE tabspace_name;' from user_tables;
二、重建索引
ALTER INDEX indx_name REBUILD ONLINE;
SEELCT 'ALTER INDEX ''||INDX_NAME||' REBUILD ONLINE;' from user_indexes;

ALTER INDEX indx_name REBUILD  PARTITION  indx_part_name TABLESPACE tablespace_name;

SELECT 'alter index '||OWNER||'.'||SEGMENT_NAME||' rebuild tablespace tabspace_name online nologging;'
 FROM  dba_segments where tablespace_name =‘tabspace_name’ AND segment_type='INDEX'

四、指定用户默认的表空间

ALTER USER "user_name"  DEFAULT TABLESPACE "TEST_SPC";

 

五、如果删除表空间之前删除了表空间文件,解决方法(oracle9i验证通过):

  $ sqlplus /nolog

  sql> conn / as sysdba;

  sql> shutdown abort

  sql> startup mount

  sql> alter datebase datafile 'datafilename' offine drop;

  sql> alter database open;

  sql> drop tablespace tablespace_name including contents;

六、在表空间联机状态下使该表空间下的数据文件脱机后,在想把脱机的数据文件联机就会报错。可以直接脱机表空间,该空间下的数据文件也变成脱机状态。

七、分区表操作

--增加分区表
 
alter table BILL_MONTHFEE_ZERO add Partition p_200409
values less than (200409) tablespace ts_ziken;

--删除一分区
alter table part_tbl drop Partition part_tbl_08;
 

--将一个分区分为两个分区
alter table bill_monthfee_zero split Partition p_200409 at (200409)
into (Partition p_200409_1 tablespace ts_ziken,
Partition p_200409_2 tablespace ts_ziken_idx);

 
--合并分区
ALTER TABLE  bill_monthfee_zero
  
MERGE PARTITIONS p_200408 , p_200409 INTO PARTITION p_all
 
--将分区改名
alter table bill_monthfee_zero rename Partition p_200408 to p_fee_200408
 
--将分区改表空间
alter table bill_monthfee_zero move Partition p_200409
tablespace ts_ziken_01 nologging
 
--查询特定分区
select count(*) from BILL_MONTHFEE_ZERO partition (p_200407);
 
--添加数据
insert into bill_monthfee_zero select * from bill_monthfee_zero partition (p_200407)
 
--分区表的导出
userid=dxsq/teledoone@jndxsq154
buffer=102400
tables=bill_monthfee:P_200401,
file=E:/exp_para/exp_dxsq_tables.dmp
log=E:/exp_para/exp_dxsq_tables.log

索引分区分为:本地(局部)索引(local index) 全局索引(global index)

一 本地索引

1.普通索引

SQL > CREATE INDEX INDEX_NAME ON TABLE (COLUMN)

local

(

partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)

2.唯一索引 如:主键

 

 

SQL > CREATE UNIQUE INDEX INDEX_NAME ON TABLE (COLUMN)

local

(

partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)

注:主键索引和主键约束的创建与删除顺序

创建主键索引 --> 创建主键约束

删除主键约束 --> 删除主键索引

3.非表分区字段唯一索引 表分区字段:USRID

SQL > CREATE UNIQUE INDEX INDEX_NAME ON TABLE (COLUMN,USRID)

local

(

partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)

 

二 全局索引

1.范围索引

SQL > CREATE [UNIQUE] INDEX INDEX_NAME ON TABLE(COLUMN)

global partition by range(column)

(

partition part_idx_01 value less than(first range value) tablespace index_space01,

partition part_idx_02 value less than(second range value) tablespace index_space02,

partition part_idx_03 value less than(maxvalue) tablespace index_space03

)

2.散列索引

SQL > CREATE [UNIQUE] INDEX INDEX_NAME ON TABLE(COLUMN,[COLUMN2])

global partition by hash(column,[column2])

(

partition part_idx_01 tablespace index_space01,

partition part_idx_02 tablespace index_space02,

partition part_idx_03 tablespace index_space03

)

 

注:

1.分区字段不是主键的情况下,只可以创建全局分区索引,不可以创建本地主键分区索引.

只有分区字段为主键时才可以创建本地主键分区索引.

2.如果创建本地唯一分区索引,除指定索引字段外还要加上表分区字段.

这种索引意义不大:因为这样构成复合索引,索引改变,约束也改变了.

3.如果创建非唯一索引则不需要表分区字段.

4.创建全局分区索引后可以创建约束.


DBA查看索引分区

select * from dba_ind_partitions

USER查看索引分区

select * from user_ind_partitions

 

DBA查看索引分区类型

select * from dba_part_indexes

USER查看索引分区类型

select * from user_part_indexes

 

 

 

 

 

 

http://space.itpub.net/7607759/viewspace-321791

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值