现在有两个表
表A 有ID YEAR 等字段。 50万数量级
表B 有表A的ID A_ID 为外键等字段 100万数量级
要求:
1。把表A的YEAR等于2009年的数据分离出来,就是建一个新表只有表A2009年的数据,并将表A中2009年的数据干掉;
2。对表B做同样的操作。以A_ID为外键。
表A 有ID YEAR 等字段。 50万数量级
表B 有表A的ID A_ID 为外键等字段 100万数量级
要求:
1。把表A的YEAR等于2009年的数据分离出来,就是建一个新表只有表A2009年的数据,并将表A中2009年的数据干掉;
2。对表B做同样的操作。以A_ID为外键。
解决方案 »
- ora 01445
- oracle中添加和删除数据时出错
- 【分享】ORACLE对象名大小写敏感性相关的深入分析
- 高分求 虚拟机配置oralcle RAC 教程
- 做一个oracle备份程序
- 用JDBC连接oracle出现的问题,请高手解答,谢谢!
- 雪地里跪求关于oracle方面的好书
- 如何修改oracle9i数据库端的字符集
- dblink, sequence and ORA-01000 maximum open cursors exceeded
- 同样一条sql,在command window中能查出数据,sql window却查不出
- exp导出时,如何对指定的多张表分别指定不同的导出条件?
- sql执行过程。。。
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.主键)
对于要求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.: 还没有想到好办法。 大家多多讨论,都有分。谢谢。
--查约束
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 --重建索引
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上加限制。