Hi ,
I have a table that contains 15lakh records.....
I want delete that table....and insert fresh set of record.
when I run the command ...db2 "delete from schema.tabname"
it hangs .......the system it seems hangs...
Is their a better way out to delete the data..
Regards
Bikash
Knut Stolze - 23 Dec 2005 08:54 GMT
> I have a table that contains 15lakh records.....
> I want delete that table....and insert fresh set of record.
>
> when I run the command ...db2 "delete from schema.tabname"
> it hangs .......the system it seems hangs...
No, it doesn't hang. It just takes a lot of time to delete every single
record. (How many records are "15 lakh"?)
An alternative is to truncate the table by importing an empty file and using
the REPLACE_INTO option for IMPORT/LOAD. Or you could install the
"truncate" procedure and call the procedure: http://tinyurl.com/9gnlo

Signature
Knut Stolze
DB2 Information Integration Development
IBM Germany
rkusenet - 23 Dec 2005 10:29 GMT
>> I have a table that contains 15lakh records.....
>> I want delete that table....and insert fresh set of record.
[quoted text clipped - 4 lines]
> No, it doesn't hang. It just takes a lot of time to delete every single
> record. (How many records are "15 lakh"?)
15 lakh = 1.5 million
Knut Stolze - 23 Dec 2005 11:30 GMT
> 15 lakh = 1.5 million
Yeah, deleting those will take a bit time with a simple DELETE
statement. ;-)

Signature
Knut Stolze
DB2 Information Integration Development
IBM Germany
Brian Tkatch - 23 Dec 2005 17:45 GMT
Because of checking on each individual record (e.g. FORIEGN KEYs) and
logging, that will take a long time.
I worked around this issue with a LOAD statement that loaded an empty
file. It will wipe the TABLE in almost no time. LOAD is a CLP command,
and may need to be followed by a SET INTEGRITY...IMMEDIATE CHECKED
statement.
If LOAD is not available, DELETEing in chunks based on the PRIMARY KEY
may be faster.
B.
Rhino - 23 Dec 2005 20:59 GMT
> Hi ,
>
[quoted text clipped - 5 lines]
>
> Is their a better way out to delete the data..
If you're on OS/390 or z/OS you should consider doing a drop of the
tablespace containing the table; I believe that this deletes the rows almost
instantly if the tablespace is of the "segmented" type.
However, be sure to verify this with a test database first; I know this was
possible in some of the earlier versions like Version 3 but I'm not
absolutely positive that it still works that way.
Of course, if you drop a segmented tablespace, you will drop _all_ of the
tables in the tablespace, not just the one you want to delete, so it would
be best if you redesigned your schema to put this large table in a segmented
tablespace of its own. You will also want to consider the impact on any
tables related to your table via referential integrity if you drop the table
(by dropping the tablespace) rather than deleting the rows.
Rhino
EDWARD LIPSON - 24 Dec 2005 20:34 GMT
The fastest way to delete the rows is with a load. If you know what
you will be inserting (in bulk), then load with that. Otherwise load
with an empty input file. This will work for all UDB.
I'm assuming that with that many rows it is a single table tablespace.
zOS Segmented Tablespac tables have special procssing for DELETE *
(resetting the page in use bits by segment), but you should issue a
LOCK TABLE first.
Remember, DELETE is a logged operation (unless you are on LUW and the
tablespace has a NOT LOGGED INITIALLY enabled and active) and logging
will be the slowest portion of the process (excluding indexes).
R > > Hi ,
R > >
R > > I have a table that contains 15lakh records.....
R > > I want delete that table....and insert fresh set of record.
R > >
R > > when I run the command ...db2 "delete from schema.tabname"
R > > it hangs .......the system it seems hangs...
R > >
R > > Is their a better way out to delete the data..
R > >
R > If you're on OS/390 or z/OS you should consider doing a drop of the
R > tablespace containing the table; I believe that this deletes the rows almost
R > instantly if the tablespace is of the "segmented" type.
R > However, be sure to verify this with a test database first; I know this was
R > possible in some of the earlier versions like Version 3 but I'm not
R > absolutely positive that it still works that way.
R > Of course, if you drop a segmented tablespace, you will drop _all_ of the
R > tables in the tablespace, not just the one you want to delete, so it would
R > be best if you redesigned your schema to put this large table in a segmented
R > tablespace of its own. You will also want to consider the impact on any
R > tables related to your table via referential integrity if you drop the table
R > (by dropping the tablespace) rather than deleting the rows.
R > Rhino
Edward Lipson via Relaynet.org Moondog
edward.lipson@moondog.com elipson@bankofny.com
---
þ MM 1.1 #0361 þ
Serge Rielau - 24 Dec 2005 23:19 GMT
> Hi ,
>
[quoted text clipped - 8 lines]
> Regards
> Bikash
ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Signature
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Knut Stolze - 27 Dec 2005 07:30 GMT
>> I have a table that contains 15lakh records.....
>> I want delete that table....and insert fresh set of record.
[quoted text clipped - 3 lines]
>>
>> Is their a better way out to delete the data..
> ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
> COMMIT;
Now that is a cool way to do the truncation. ;-)

Signature
Knut Stolze
DB2 Information Integration Development
IBM Germany
Serge Rielau - 28 Dec 2005 00:58 GMT
>>>I have a table that contains 15lakh records.....
>>>I want delete that table....and insert fresh set of record.
[quoted text clipped - 8 lines]
>
> Now that is a cool way to do the truncation. ;-)
Indeed. Widely unknown for some uncomprehensible reason.
Folks keep yacking about TRUNCATE TABLE and 90% of what it does is
right there....
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Mark Townsend - 28 Dec 2005 01:02 GMT
>>> ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
>>> COMMIT;
>>
> Indeed. Widely unknown for some uncomprehensible reason.
Perhaps because it's uncomprehensible ?
Serge Rielau - 28 Dec 2005 02:43 GMT
>>>> ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
>>>> COMMIT;
>>>
>> Indeed. Widely unknown for some uncomprehensible reason.
>
> Perhaps because it's uncomprehensible ?
No less so, than LOAD REPLACE with an empty file.
Mark,
I thought we had some agreement that we either post in competitive
newgroups to clarify misconceptions or to be constructive.
Did the rules change?
Your noise to data ratio is quite high these days..
I don't have to play nice ein c.d.oracle.* either...
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Mark Townsend - 28 Dec 2005 03:34 GMT
> Your noise to data ratio is quite high these days..
Really ? - and here I am thinking I've been good. Dang.