zoukankan      html  css  js  c++  java
  • set unused的用法(ORACLE删除字段)

    set unused的用法(ORACLE删除字段)

    一、问题

    现场有一张大数据量的分区表,数据量在10G以上。因某种原因需要删除其中的某些字段。如果直接用
    alter table1 drop (column1,column2);
    或者alter table1 drop column column1;和alter table1 drop column column2; 
    的话,需要执行很长时间,这期间该表被锁,会影响到其它应用。

    二、解决方法

    使用set unused,等系统空闲时再drop unused。

    1.

    alter table table1 set unused (column1,column2);
    或者
    alter table table1 set unused column column1;
    alter table table2 set unused column column2;

    2.

    alter table drop unused columns checkpoint 1000;

    三、知识点(set unused的用法)

    原理:清楚掉字典信息(撤消存储空间),不可恢复。

    可以使用 SET UNUSED 选项标记一列或者多列不可用。
    使用DROP SET UNUSED 选项删除被标记为不可用的列。

    语法:

    ALTER TABLE table SET UNUSED (COLlist多个) 或者 ALTER TABLE table SET UNUSED COLUMN col单个;

    ALTER TABLE table DROP UNUSED COLUMNS [checkpoint 1000];

    set unused不会真地删除字段。

    除了alter table drop field外,也可以
    alter table set unused field;
    alter table drop unused;

    set unused系统开销比较小,速度较快,所以可以先set unused,然后在系统负载较小时,再drop。如系统负载不大,也可以直接drop。

    不管用何种方法,都不会收回空间。

    如果你有这个需求,要删除某一个表上的某些列,但是由于这个表拥有非常大量的资料,如果你在尖峰时间直接执行 ALTER TABLE ABC DROP(COLUMN);可能会收到
    ORA-01562 - failed to extend rollback segment number string,
    这是因为在这个删除列的过程中你可能会消耗光整个RBS,造成这样的错误出现,因此这样的做法并不是一个好方法,就算你拼命的加大RBS空间来应付这个问题,也不会是个好主意。

    我的建议做法:

    1>
    CREATE TABLE T1 (A NUMBER,B NUMBER);

    SQL> begin
    2 for i in 1 …… 100000
    3 loop
    4 insert into t1 values (i,100);
    5 end loop;
    6 commit;
    7 end;

    SQL> select count(*) from t1;

  • 相关阅读:
    eventkeyboardmouse
    代理 IP
    网关 192.168.2.1 114.114.114.114 dns查询
    http ssl
    SSDP 抓包
    抓包登录信息提交
    危险的input 微博的过去
    firstChild.nodeValue
    浏览器控制台
    haproxy 中的http请求和https请求
  • 原文地址:https://www.cnblogs.com/CandiceW/p/10036892.html
Copyright © 2011-2022 走看看