四个脚本,用于表和索引转移表空间的操作

本文提供了一个SQL脚本,用于批量转移数据库表和索引的表空间,包括普通表、分区表、普通索引和分区索引。
/*该脚本可以生成SQL,将SQL粘出来,就可以执行了*/

--转移普通表的表空间
select 'alter table ' || t1.table_name || ' move tablespace NEW_TBS;'
from user_all_tables t1
where t1.tablespace_name = 'OLD_TBS';

--转移分区表的表空间
select 'alter table ' || t1.table_name || move partition ' ||
t2.partition_name || ' tablespace NEW_TBS;' || chr(13) ||
'commit;'
from user_all_tables t1, user_tab_partitions t2
where t1.table_name = t2.table_name
and t2.tablespace_name = 'OLD_TBS';

--转移普通索引
select 'alter index' || t.INDEX_NAME || ' rebuild tablespace NEW_TBS;'
from user_indexes t
where t.index_type = 'NORMAL'
and t.DROPPED = 'NO'
and t.TABLE_NAME in
(select a.table_name
from user_all_tables a
where a.tablespace_name = 'OLD_TBS');

--转移分区索引
select 'alter index ' || t1.index_name || ' rebuild partition ' ||
t2.partition_name || 'tablespace NEW_TBS;'
from user_indexes t1, user_ind_partitions t2
where t1.INDEX_NAME = t2.index_name
and t2.tablespace_name = 'OLD_TBS'

转载于:https://www.cnblogs.com/wingsless/archive/2011/11/30/2269401.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值