I'm new to DB2. I want to remove large number of rows in a table
without filling up the transaction log space. To this end we can
repeatedly remove a fixed number of rows followed by commit. In
Sybase, one can write a simple transact SQL using rowcount and while
loop to. I saw several people suggesting similar ways in DB2 to
achieve this. I tried to write a compound SQL but failed to get it
work. Haven't been able to get the syntax right.
Can anybody please advise how to get it right? Thanks!
BEGIN ATOMIC
DECLARE rows_deleted INT default 1;
WHILE rows_deleted 0 DO
delete from myTable t
where t.prodID in
(select p.prodID from tableB b
where t.vendor = b.vendor
fetch first 1000 rows only);
commit;
get diagnostics rows_deleted = row_count;
END WHILE;
END
Comment