有个表中记录有100万条左右,怎么样才能快速将复合条件的记的某个字段改成一个新值?
如下:
update table1 set flag=1 where flag=0

解决方案 »

  1.   

    flag字段已经建了索引了,主要问题是如果update的记录数过多,数据库的回滚段要求就很大,怎么才能update而不使用回滚段?
      

  2.   

    我的意思是有没有方法不用回滚段?也就是在update的时候不开启一个事务.
      

  3.   


     晕...
     update时如果不开启事务,数据丢失了或者误改了怎么办?  可以批量更新, 每更新小批量数据例如1000条时就提交一次.
      

  4.   

    If I had to update millions of records I would probably opt to NOT update.I would more likely do:CREATE TABLE new_table as select <do the update "here"> from old_table;index new_table
    grant on new table
    add constraints on new_table
    etc on new_tabledrop table old_table
    rename new_table to old_table;
    you can do that using parallel query, with nologging on most operations 
    generating very little redo and no undo at all -- in a fraction of the time it 
    would take to update the data.
      

  5.   


     批量更新很快的, TOM 也推荐这种做法, 如果仍然很慢的话, 估计
     是你的应用的问题. 楼上写的方式也可用。