insert into b(col1,col2..) select cola,colb.. from a where ...;是这个意思吗?
insert into b(col1,col2..) select cola,colb.. from a
如果不考虑删除数据与插入数据是否完全一致的情况,insert into b(col1,col2..) select cola,colb.. from a where ...; delete from a where ...; commit;即可。
你操作的过程是什么,查询->插入->?->删除?是什么
insert into b select * from a; commit; delete; commit;
我的工作流程是:查询-》插入-》删除 插入完毕后,将使用查询使用的条件,删除数据; 但是,使用insert into ... select 这样的语句,如果遇到了插入失败(记录重复),这样的情况下,系统会怎么处理? 会自动放弃重复记录的插入,并继续其他记录的插入否?
放弃插入。 重复记录应当在 insert into ... select ...where not exists(select .. from B where b...=a...)(这个地方来控制)
insert into t2(tt) select tt from t1 where not exists(select b.tt from t1 a,t2 b where b.tt=a.tt);t1中的值为: 1 2 5 t2中的值为: 1 2执行以后,没有插入记录啊;
应该是: insert into t2(tt) select tt from t1 where not exists(select b.tt from t2 b where b.tt=a.tt);你原来的条件:select b.tt from t1 a,t2 b where b.tt=a.tt 永远为TRUE
delete from a where ...;
commit;即可。
commit;
delete;
commit;
插入完毕后,将使用查询使用的条件,删除数据;
但是,使用insert into ... select
这样的语句,如果遇到了插入失败(记录重复),这样的情况下,系统会怎么处理?
会自动放弃重复记录的插入,并继续其他记录的插入否?
重复记录应当在
insert into ... select ...where not exists(select .. from B where b...=a...)(这个地方来控制)
t1 a,t2 b where b.tt=a.tt);t1中的值为:
1
2
5
t2中的值为:
1
2执行以后,没有插入记录啊;
insert into t2(tt) select tt from t1 where not exists(select b.tt from t2 b where b.tt=a.tt);你原来的条件:select b.tt from t1 a,t2 b where b.tt=a.tt 永远为TRUE
可以一条一条查出来,包含ROWID,全放到变量中,处理后INSERT进另一张表就行了
删除时用ROWID做条件,又快又可靠
insert into t2(tt) select tt from t1
where not exists(select 1 from
t1 a where b.tt=a.tt);
如果有重复数据可用bzszp(SongZip)说的
insert into ... select ...where not exists(select .. from B where b...=a...)
但是怀疑速度慢t1里面的数据是有百W级的
改帖建议放到精华区;