473,626 Members | 3,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8385
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...@gmai l.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...@gmai l.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...@yah oo.comwrote:
Thanks a lot! *Is it possible to do the same without creating a stored
proc?

On Jul 23, 4:34*pm, db2dude <abhyan...@gmai l.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
3319
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 query: SELECT DISTINCT , , ,City, Region FROM Customers ORDER BY Customers.; This was working fine until a couple of weeks ago. Now whenever someone has the form open, this statement locks the entire Customers table.
57
25499
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
2175
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 0.5 million rows, 8 million rows, 14 & 29 million rows as well. How do I categorize them? Any comments will be helpful.
24
21574
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 logic in place that, prior to inserting any data, reads the first input record and checks to see if it already exists in the table. If the record already exists there are two options: 1) Don't continue, because you already ran this job today! 2)...
2
2429
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 the user to edit and update records from that interface. I have cached some static lists in the page but the main recordset should reflect updated data so it can't be cached. I also compute some control functions over the whole data. This will...
3
12321
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 other reading/deleting rows. The 'deleter' application runs a MIN/MAX (timestamp) for each ID and, if the difference between min/max is greater than 1h, it reads all
6
7988
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, call determined functions, and edit the data already present What will you need to use the grid? A table with standard markup and an ID to call the script that will turn the table into a grid Parameters: tabelaID => id of the table that will...
7
2634
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 on the size of the object, a large number of rows. I then need to rotate it and write the new position of the object to a new .raw file. I started with a box as a simple example that had only 28 rows. The code worked fine for the small number of...
2
3666
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 fixed set of rows until there is no more to remove. However db2 complains about bad syntax. Can anybody advise how I get it right? Thanks!
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8701
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.