现在有两个表
表A 有ID  YEAR 等字段。 50万数量级
表B 有表A的ID A_ID 为外键等字段  100万数量级
要求:
1。把表A的YEAR等于2009年的数据分离出来,就是建一个新表只有表A2009年的数据,并将表A中2009年的数据干掉;
2。对表B做同样的操作。以A_ID为外键。

解决方案 »

  1.   

    create table abak as select * from a where a.year=2009;
    delete a where a.year=2009;
    create table bbak as select b.* from a,b where a.id=b.a_id and a.year=2009;
    delete b where exists(select 1 from bbak where bbak.主键=b.主键) 
      

  2.   

    自己顶一个先
    对于要求1:第一步不难
    create table tb2009 as select * from a where 1=2;
    insert /*+append*/ into tb2009 select * from a where year=2008;第二步 怎么栓除A表中2008年的数据呢 用delete from a where year=2008 ; 这样太慢啊要求2.: 还没有想到好办法。 大家多多讨论,都有分。谢谢。
      

  3.   


    --查约束
    set long 1000 
    select dbms_metadata.get_ddl('TABLE','A','USERNAME') from dualcreate table A2009 as select * from A where 1<>1
    alter table A2009 add constraint....加约束
    --不写入日志
    alter table A2009 nologging
    insert /*+append*/ into A2009 select * from A where year='2009'
    alter table A2009 logging--删除老数据
    alter index idx_name unusable --禁用索引
    alter table A nologing
    --批量删除
    decalre
    num number;
    begin
    while 1=1 loop
    delete from A where year='2009' where rownum<=10000;
    commit;
    if sql%notfound then
    exit;
    end if;
    end loop;
    end;alter index idx_name rebuild --重建索引
      

  4.   

    create table c as select * from a where 1=2;
    insert /*+ append */ into c select * from A where year='2009';
    commit;create table d as select * from a where 1=2;
    insert /*+ append */ into d select * from A where year<>'2009';
    commit;drop table A;
    rename d to A;
    然后在A上加限制。