473,395 Members | 1,647 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,395 software developers and data experts.

Doing updates/deletes in small batches...

I know this subject has come up many times but I am not finding what I
am looking for after a couple days of searching. I know some months
ago I saw an indirect solution for this but I cant seem to find it now
that I need it.

This is DB2 UDB V8.2 on AIX 5.3

I need to create a script (ksh) to update a large number of records.
This could be a million records so I need to do it in smaller chunks to
avoid the logging problem. I cant seem to find a way in DB2 to limit
the number of records I am deleting at a time. The tables do not have
a recnum type column that I can use to select by. I cannot add a new
column just for this purpose either since the tool is just to be used
to do some testing cleanup.
What I want to do is pretty basic:

db2 "UPDATE table1 SET column2 = -1" //for all records

or to reduce further:

db2 "UPDATE table1 SET column2 = -1 WHERE column2 <-1" //to only do
the ones that are not already set to that value

But I would like to do it in increments of 1000 records and commit. I
dont see a way to LIMIT 1000 or FIND FIRST 1000 in DB2.

I could SELECT all records by primarykey (this is a char value) and put
it in a file then do individual updates on each record, committing
every 1000 count but this seems like a very tedious, ineffecient way to
do it.

So...anyone have a better way?

Aug 3 '06 #1
3 19933
I think Serge has posted some time back....some stored procedures...to
do this
CREATE PROCEDURE DELETE_LOADS_OF_ROWS (TABSCHEMA VARCHAR(64), TABNAME
VARCHAR(64), PREDICATE VARCHAR(256), COMMITCOUNT INTEGER) BEGIN
DECLARE SQLCODE INTEGER;
DECLARE txt VARCHAR(512);
DECLARE stmt STATEMENT;
SET txt = 'DELETE FROM (SELECT 1 FROM "'|| TABSCHEMA || '"."' ||
TABNAME || '" WHERE '|| PREDICATE || ' FETCH FIRST ' ||
RTRIM(CHAR(COMMITCOUNT)) || ' ROWS ONLY) AS D';
PREPARE stmt FROM txt;
l: LOOP
EXECUTE stmt;
IF SQLCODE = 100 THEN LEAVE l; END IF;
COMMIT;
END LOOP;
COMMIT;
END
%
cheers...
Shashi Mannepalli

shorti wrote:
I know this subject has come up many times but I am not finding what I
am looking for after a couple days of searching. I know some months
ago I saw an indirect solution for this but I cant seem to find it now
that I need it.

This is DB2 UDB V8.2 on AIX 5.3

I need to create a script (ksh) to update a large number of records.
This could be a million records so I need to do it in smaller chunks to
avoid the logging problem. I cant seem to find a way in DB2 to limit
the number of records I am deleting at a time. The tables do not have
a recnum type column that I can use to select by. I cannot add a new
column just for this purpose either since the tool is just to be used
to do some testing cleanup.
What I want to do is pretty basic:

db2 "UPDATE table1 SET column2 = -1" //for all records

or to reduce further:

db2 "UPDATE table1 SET column2 = -1 WHERE column2 <-1" //to only do
the ones that are not already set to that value

But I would like to do it in increments of 1000 records and commit. I
dont see a way to LIMIT 1000 or FIND FIRST 1000 in DB2.

I could SELECT all records by primarykey (this is a char value) and put
it in a file then do individual updates on each record, committing
every 1000 count but this seems like a very tedious, ineffecient way to
do it.

So...anyone have a better way?
Aug 3 '06 #2
If u want to use SHELL script...

u can find first 1000 rows like this...

db2 "select * from <tablefetch first 1000 rows only"

u can ROWNUMBER function also.

cheers...
Shashi Mannepalli
shorti wrote:
I know this subject has come up many times but I am not finding what I
am looking for after a couple days of searching. I know some months
ago I saw an indirect solution for this but I cant seem to find it now
that I need it.

This is DB2 UDB V8.2 on AIX 5.3

I need to create a script (ksh) to update a large number of records.
This could be a million records so I need to do it in smaller chunks to
avoid the logging problem. I cant seem to find a way in DB2 to limit
the number of records I am deleting at a time. The tables do not have
a recnum type column that I can use to select by. I cannot add a new
column just for this purpose either since the tool is just to be used
to do some testing cleanup.
What I want to do is pretty basic:

db2 "UPDATE table1 SET column2 = -1" //for all records

or to reduce further:

db2 "UPDATE table1 SET column2 = -1 WHERE column2 <-1" //to only do
the ones that are not already set to that value

But I would like to do it in increments of 1000 records and commit. I
dont see a way to LIMIT 1000 or FIND FIRST 1000 in DB2.

I could SELECT all records by primarykey (this is a char value) and put
it in a file then do individual updates on each record, committing
every 1000 count but this seems like a very tedious, ineffecient way to
do it.

So...anyone have a better way?
Aug 3 '06 #3
Thanks. The "fetch first 1000 rows only" In the initial post rung a
few bells. I am just going to do a:

db2 "update (select column2 from table1 where column2 <-1 fetch first
1000 rows only) set column2 = -1"

db2 commit

Then loop it until I get an SQL0100W.
Thanks!

That was exactly what I was looking for!

Aug 3 '06 #4

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

Similar topics

2
by: Warren Wright | last post by:
Hi All, First, where can I get some questions of this sort answered? Preferably, are there good books or online guides that I can consult for these types of answers when necessary? 1. How do...
1
by: peter | last post by:
Hi All, a quick question. I haven't used DB2 on mainframe since 1995 so my memory is fading a bit. But I seem to recall DB2/MVS having the ability to perform unlogged deletes. Situation is I...
0
by: Frnak McKenney | last post by:
One part of a customer project I'm working on involves what seem like fairly straightforward updates to a set of related tables. While I've developed software for a number of years (it only seems...
1
by: Mark Harrison | last post by:
I can't seem to get PG into non-blocking mode. Here is the result I'm getting from the code attached below. I'm expecting to get multiple "PQntuples=" lines, but instead I'm getting just one...
2
by: mslabelle | last post by:
I’m new to Oracle (PL/SQL), and have very little real world experience. But I’ve been met with a challenge. It’s quite interesting and I know I can meet it with a little help/direction. We...
0
by: Dimitris Milonas | last post by:
Hello to all, I have a DetailView on a page with Insert/Update enable and Paging enable. I would like to have on the same page two buttons ("Submit" and "Cancel") where with the first ("Submit")...
8
by: Bob Alston | last post by:
I just acquired a pro bono nonprofit client who has various problems with Access that they want me to address. In our initial discussion, they mentioned that their network is a LInksys wireless...
2
by: tc | last post by:
Hi All. What is the vb.net way of supplying updates for applications? Just sending out an updated exe looks a bit sloppy. Cheers.
4
by: shreyask | last post by:
I have been working on doing bulk updates and inserts through sqlapi++ using a bulk udpate extention library, developed, a long time ago, internally. The database is oracle. The bulk inserts/updates...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...

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.