View Single Post

   
  #1 (permalink)  
Old 05-11-2008, 08:41 PM
Michel Esber
 
Posts: n/a
Default Update Statement and frequent commits

Hello,

DB2 v8 FP15 luw.

Serge´s SQL on Fire has the following code for granular commits on
delete statements:

loop: LOOP
DELETE FROM (SELECT 1 FROM T WHERE ID = ? FETCH FIRST 1000 ROWS
ONLY) AS D;
IF SQLCODE = 100 THEN LEAVE loop;
END IF;
COMMIT;
END LOOP loop;


I want to achieve the same for Update statements on multi million
tables. My first try is:


loop: LOOP
update from T where ID IN

(
select ID from
(select ID, rownumber() over (partition by ID order by ID desc) as
RN from T where ID = ? ) as x
where rn <= 1000
)

IF SQLCODE = 100 THEN LEAVE loop;
END IF;
COMMIT;
END LOOP loop;



Any better suggestion or approach ?

Thanks, Michel
Reply With Quote