473,378 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

remove large number of rows using SQL only


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
Jul 23 '08 #1
5 8356
You cannot commit inside an atomic compound statement (begin atomic).

Try doing the same inside a stored procedure (with "begin" instead of
"begin atomic" ).

something on these lines...

create procedure xx.yyyy ()
language sql
begin
declare delcount integer default 0;

repeat
delete from (
select 1
from <schema>.<table>
fetch first 1000 rows only
);
get diagnostics delcount = row_count;
commit;
until delcount = 0
end repeat;
end;
Hope that helps.

-SA
Jul 23 '08 #2

Thanks a lot! Is it possible to do the same without creating a stored
proc?

On Jul 23, 4:34*pm, db2dude <abhyan...@gmail.comwrote:
You cannot commit inside an atomic compound statement (begin atomic).

Try doing the same inside a stored procedure (with "begin" instead of
"begin atomic" ).

something on these lines...

create procedure xx.yyyy ()
language sql
begin
* *declare delcount integer default 0;

* *repeat
* *delete from (
* * * * * * *select 1
* * * * * * *from <schema>.<table>
* * * * * * *fetch first 1000 rows only
* *);
* *get diagnostics delcount = row_count;
* *commit;
until delcount = 0
end repeat;

end;

Hope that helps.

-SA
Jul 24 '08 #3

Thanks a lot! Is it possible to do the same without creating a stored
proc?

On Jul 23, 4:34*pm, db2dude <abhyan...@gmail.comwrote:
You cannot commit inside an atomic compound statement (begin atomic).

Try doing the same inside a stored procedure (with "begin" instead of
"begin atomic" ).

something on these lines...

create procedure xx.yyyy ()
language sql
begin
* *declare delcount integer default 0;

* *repeat
* *delete from (
* * * * * * *select 1
* * * * * * *from <schema>.<table>
* * * * * * *fetch first 1000 rows only
* *);
* *get diagnostics delcount = row_count;
* *commit;
until delcount = 0
end repeat;

end;

Hope that helps.

-SA
Jul 24 '08 #4
On Jul 24, 12:36*pm, "Henry J." <tank209...@yahoo.comwrote:
Thanks a lot! *Is it possible to do the same without creating a stored
proc?

On Jul 23, 4:34*pm, db2dude <abhyan...@gmail.comwrote:
You cannot commit inside an atomic compound statement (begin atomic).
Try doing the same inside a stored procedure (with "begin" instead of
"begin atomic" ).
something on these lines...
create procedure xx.yyyy ()
language sql
begin
* *declare delcount integer default 0;
* *repeat
* *delete from (
* * * * * * *select 1
* * * * * * *from <schema>.<table>
* * * * * * *fetch first 1000 rows only
* *);
* *get diagnostics delcount = row_count;
* *commit;
until delcount = 0
end repeat;
end;
Hope that helps.
-SA
I dont think that is possible since you would need to issue a 'commit'
statement you will not be able to do that inside a dynamic compound
sql (begin atomic .. end)

- SA
Jul 24 '08 #5
You can drive the loop from the client in any language you wish.
Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 24 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roy Padgett | last post by:
I have a combo box where users select the customer name and can either go to the customer's info or open a list of the customer's orders. The RowSource for the combo box was a simple pass-through...
57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
2
by: shsandeep | last post by:
Hi all, I have heard and read this many times: "Partitions should only be used for 'very large' tables". What actually determines whether a table is 'very large' or not? I have tables containing...
24
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have...
2
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, I'm faced with a classic problem of how to update a large number of records from a web page. I;m trying to build an interface that will display recordset in the order of 3000 rows and allow...
3
by: Michel Esber | last post by:
Hello, Environment: DB2 LUW v8 FP15 / Linux I have a table with 50+ Million rows. The table structure is basically (ID - Timestamp). I have two main applications - one inserting rows, and the...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
7
by: abunn | last post by:
I've been learning Visual C++ on the fly at work for the last 2 weeks and could use some help. I'm writing a program to read a .raw file which has a standard format of 9 columns and then depending...
2
by: Henry J. | last post by:
I'm DB2 newbie. I need to remove large number of rows from a table. I don't want to fill up the transaction log space. I have the below SQL that I feed to the db2 command to repeatly remove a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.