Re: Delete Huge Number Of Rows Failed

This is a discussion on Re: Delete Huge Number Of Rows Failed within the db2-udb forums in Other Databases category; Dear Sir , Thanks for your immediate reply . Here is my situation , i am trying to delete based on a specific condition as follows : delete from MQSISIS.ASI_REQ_LOG where DAYS(current timestamp)-DAYS(DATE_0)>2 iw ant to delete all the transactions that are 2 days history and keep the other inside the table. Estimate no of rows is 1 million and the deleted is about 250000 every day So how can i produce a procedure to handle this request Best regards...

Go Back   Database Forum > Other Databases > db2-udb

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 12-21-2006, 07:13 AM
Default Re: Delete Huge Number Of Rows Failed

Dear Sir ,
Thanks for your immediate reply .

Here is my situation , i am trying to delete based on a specific condition
as follows :
delete from MQSISIS.ASI_REQ_LOG where DAYS(current timestamp)-DAYS(DATE_0)>2
iw ant to delete all the transactions that are 2 days history
and keep the other inside the table.
Estimate no of rows is 1 million and the deleted is about 250000 every day

So how can i produce a procedure to handle this request

Best regards

Reply With Quote
  #2  
Old 12-21-2006, 08:00 AM
Default Re: Delete Huge Number Of Rows Failed

abdelhakeem Sabih wrote:

> Dear Sir ,
> Thanks for your immediate reply .
>
> Here is my situation , i am trying to delete based on a specific condition
> as follows :
> delete from MQSISIS.ASI_REQ_LOG where DAYS(current
> timestamp)-DAYS(DATE_0)>2 iw ant to delete all the transactions that are 2
> days history and keep the other inside the table.
> Estimate no of rows is 1 million and the deleted is about 250000 every day
>
> So how can i produce a procedure to handle this request


A couple ideas that I had immediately:

DECLARE c1 CURSOR WITH HOLD FOR SELECT ...
OPEN c1
while
DELETE WHERE CURRENT OF c1
COMMIT every n records


Another idea is to select just a few rows and delete those. Repeat that
until nothing gets deleted any longer:

loop until #affected rows = 0
DELETE
FROM ...
WHERE id IN ( SELECT id
FROM ...
WHERE ...
FETCH FIRST n ROWS ONLY )

Or you can use the row_number function instead of FETCH FIRST n ROWS ONLY.

Yet another approach could be range partitioning tables. A simple
DETACH/DROP could take care of the DELETE operation. But that may result
in more administrative overhead to maintain the various ranges on your
resolution.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Reply With Quote
  #3  
Old 12-21-2006, 11:54 AM
Default Re: Delete Huge Number Of Rows Failed

Dear Sir ,

Thanks For your reply .
would you please write this procedure for me, becuase i am new at DB2
i will appreciate this a lot .

Regards

Reply With Quote
  #4  
Old 01-14-2007, 01:56 AM
Default Re: Delete Huge Number Of Rows Failed

Urgent Call ,
Can Anybody Help My In Producing a Stored Procedure That Can Delete Million Record


Regards
Reply With Quote
  #5  
Old 01-16-2007, 12:15 PM
Default Re: Delete Huge Number Of Rows Failed

taking the approach of Knut here is your procedure:



-- file: MQSISIS_del_history.sql
--
-- make with: db2 -td@ -f MQSISIS_del_history.sql
--
-- execute with: db2 "call MQSISIS.del_history ()"

create procedure MQSISIS.del_history ()
language sql

begin
declare commit_count integer default 3;
declare row_no integer default 0;

for f1 as c1 cursor with hold for select *
from MQSISIS.ASI_REQ_LOG
where DAYS(current timestamp)-DAYS(DATE_0)>2
do
set row_no = row_no + 1;
delete from MQSISIS.ASI_REQ_LOG where current of c1;
if (row_no = commit_count) then
set row_no = 0;
commit;
end if;
end for;
end@


Don't forget to put in your desired value for commit_count


cheers
aka.

Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 05:51 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Integrated by bbpixel2009 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.