oracle里如何快速drop column测试(慎用于生产系统,该操作导致表无法访问)

oracle里如何快速drop column测试
2009-05-20 11:21
平台: oracle 10.2.0.1

直接DROP COLUMN操作:

create table u_test.t2 as select rownum c1, rownum + 1 c2, 'test'||rownum c3 from dual connect by level <= 20000000;
--Elapsed: 00:02:06.61

ALTER TABLE u_test.t2 DROP COLUMN c1;
--Elapsed: 00:13:10.53

先SET UNUSED然后DROP UNUSED COLUMNS操作,效率上只有些许的提升:


create table u_test.t1 as select rownum c1, rownum + 1 c2, 'test'||rownum c3 from dual connect by level <= 20000000;
--Elapsed: 00:03:41.98

alter table u_test.t1 SET UNUSED (c1);
--Elapsed: 00:00:00.08

select * from DBA_UNUSED_COL_TABS;
OWNER           TABLE_NAME                          COUNT
--------------- ------------------------------ ----------
U_TEST          T1                                      1

ALTER TABLE u_test.t1 DROP UNUSED COLUMNS;
--Elapsed: 00:12:08.09

先SET UNUSED然后DROP UNUSED COLUMNS操作,并设置指定的CHECKPOINT,效率上也只有些许的提升:


alter table u_test.t1 SET UNUSED (c2);
--Elapsed: 00:00:00.24

ALTER TABLE u_test.t1 DROP UNUSED COLUMNS CHECKPOINT 512;
--Elapsed: 00:11:51.11

但是只要把列置为unused, 则可以当作表没有了该列, 这算是最快方式. 逻辑删除好处就是可以当资源紧张的时候节约处理时间, 当以后空余的时间再真正DROP掉. 注意DROP UNUSED COLUMNS的时候会有最高级的排它锁, 所以要在停业务的情况下进行.

create table u_test.t3 (c1 number, c2 varchar2(10));
alter table u_test.t3 modify c1 not null;
insert into u_test.t3 values (1,'test1');
commit;

alter table u_test.t3 set unused (c1);
desc u_test.t3;
Name             Null?    Type
---------------- -------- -----------------
C2                        VARCHAR2(10)

insert into u_test.t3 values (2,'test2');
ERROR at line 1:
ORA-00913: too many values

insert into u_test.t3 values ('test2');  
1 row created.
commit;

--End--
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值