473,608 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

truncate in db2

Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a high
record count without using "load" and is fast?

Thanks,
Sumanth
Feb 15 '06 #1
9 14686
Sumanth wrote:
Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a high
record count without using "load" and is fast?

ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 15 '06 #2
Serge Rielau wrote:
Sumanth wrote:
Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a
high record count without using "load" and is fast?


ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Cheers
Serge


What happens if someone else is using the table at the same time?
--
Daniel A. Morgan
http://www.psoug.org
da******@x.wash ington.edu
(replace x with u to respond)
Feb 15 '06 #3
>What happens if someone else is using the table at the same time?
In a data warehouse environment, we force the lockholder off to do the
Alter Table Activate....Thi s is a standard part of our daily and weekly
data maintenance.

I would defer to Serge on this, but I THINK you could also do an online
(allow read access) load of an empty cursor for a slightly more elegant
solution.

Pete H

Feb 15 '06 #4
Thanks Serge.

For this to be executed within the application code would require the
application-db2-user to have alter privileges.. is it a good practice?

Also is truncate being planned for future DB2 implementations .

Thanks for your time and help.

Thanks,
Sumanth

"Serge Rielau" <sr*****@ca.ibm .com> wrote in message
news:45******** ****@individual .net...
Sumanth wrote:
Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a high
record count without using "load" and is fast?

ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

Feb 15 '06 #5
DA Morgan wrote:
Serge Rielau wrote:
Sumanth wrote:
Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a
high record count without using "load" and is fast?

ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Cheers
Serge

What happens if someone else is using the table at the same time?

Good question. I guessed the answer, but still felt compelled to test.
It's just a regular DDL statement.
ALTER TABLE will have to wait until that someone else is done.

Session 1:
db2 => connect to test;

Database Connection Information

Database server = DB2/NT Viper
SQL authorization ID = SRIELAU
Local database alias = TEST

db2 => update command options using c off;
DB20000I The UPDATE COMMAND OPTIONS command completed successfully.
db2 => declare cur1 cursor for select * from a3;
DB20000I The SQL command completed successfully.
db2 => open cur1;
DB20000I The SQL command completed successfully.
--- Run session 2 here
db2 => close cur1;
DB20000I The SQL command completed successfully.
db2 => open cur1;
-- Wait for session 2 to commit
DB20000I The SQL command completed successfully.

session 2:
db2 => connect to test;

Database Connection Information

Database server = DB2/NT Viper
SQL authorization ID = SRIELAU
Local database alias = TEST

db2 => alter table a3 activate not logged initially with empty table;
-- Waits for session 1
-- returns when cursor is closed
DB20000I The SQL command completed successfully.
db2 => commit;

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 15 '06 #6
DA Morgan wrote:
Serge Rielau wrote:
Sumanth wrote:
Are there any implementations of truncate in db2. Is it going to be
implemented in the future?

Is there an alternate way of doing a truncate of a table that has a
high record count without using "load" and is fast?

ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
COMMIT;

Cheers
Serge

What happens if someone else is using the table at the same time?

Good question. I guessed the answer, but still felt compelled to test.
It's just a regular DDL statement.
ALTER TABLE will have to wait until that someone else is done.

Session 1:
db2 => connect to test;

Database Connection Information

Database server = DB2/NT Viper
SQL authorization ID = SRIELAU
Local database alias = TEST

-- turn of auto commit
db2 => update command options using c off;
DB20000I The UPDATE COMMAND OPTIONS command completed successfully.
db2 => declare cur1 cursor for select * from a3;
DB20000I The SQL command completed successfully.
db2 => open cur1;
DB20000I The SQL command completed successfully.
--- Run session 2 here
db2 => close cur1;
DB20000I The SQL command completed successfully.
db2 => open cur1;
-- Wait for session 2 to commit
DB20000I The SQL command completed successfully.

session 2:
db2 => connect to test;

Database Connection Information

Database server = DB2/NT Viper
SQL authorization ID = SRIELAU
Local database alias = TEST

-- turn of auto commit
db2 => update command options using c off;
DB20000I The UPDATE COMMAND OPTIONS command completed successfully.
db2 => alter table a3 activate not logged initially with empty table;
-- Waits for session 1
-- returns when cursor is closed
DB20000I The SQL command completed successfully.
db2 => commit;
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 15 '06 #7
Sumanth wrote:
Thanks Serge.

For this to be executed within the application code would require the
application-db2-user to have alter privileges.. is it a good practice?

Also is truncate being planned for future DB2 implementations .

Eventually. I'm not sure whether a hypothetical TRUNCATE will only
require DELETE privileges.
It's a pretty big gun to unrecoverably wipe a table, and ignore triggers..
After all I assume you do not want to simple have TRUNCATE be a
"DELETE FROM T", right?

Interstingly I tried to see if you can work around it, but DB2 is
quite paranoid at this particluar point:

db2 => --#SET TERMINATOR $
db2 => DROP SPECIFIC PROCEDURE TRUNCATE
db2 (cont.) => $
DB20000I The SQL command completed successfully.
db2 => CALL SYSPROC.SET_ROU TINE_OPTS('DYNA MICRULES BIND')
db2 (cont.) => $

Return Status = 0

db2 => CREATE PROCEDURE TRUNCATE(IN tabschema VARCHAR(128),
db2 (cont.) => IN tabname VARCHAR(128))
db2 (cont.) => SPECIFIC TRUNCATE
db2 (cont.) => BEGIN
db2 (cont.) => DECLARE txt VARCHAR(1000);
db2 (cont.) => SET txt = 'ALTER TABLE "' || tabschema || '"."'
db2 (cont.) => || tabname || '" ACTIVATE NOT LOGGED'
db2 (cont.) => || ' INITIALLY WITH EMPTY TABLE';
db2 (cont.) => EXECUTE IMMEDIATE txt;
db2 (cont.) => COMMIT;
db2 (cont.) => END
db2 (cont.) => $
DB20000I The SQL command completed successfully.
db2 => CALL SYSPROC.SET_ROU TINE_OPTS(CAST( NULL AS VARCHAR(1)))
db2 (cont.) => $

Return Status = 0

db2 => GRANT EXECUTE ON PROCEDURE TRUNCATE TO JOE
db2 (cont.) => $
DB20000I The SQL command completed successfully.
db2 => --#SET TERMINATOR ;
db2 => call truncate('SRIEL AU', 'A3');
SQL0549N The "ALTER" statement is not allowed for "package" "P7300390"
because the bind option DYNAMICRULES RUN is not in effect for the "package".
SQLSTATE=42509

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 15 '06 #8
Just a passing comment ... using ALTER TABLE ... in this manner will make the
table non-recoverable in the event you are using log retention if I am not
mistaken. Something to consider.

Bob
"Serge Rielau" <sr*****@ca.ibm .com> wrote in message
news:45******** ****@individual .net...
| Sumanth wrote:
| > Are there any implementations of truncate in db2. Is it going to be
| > implemented in the future?
| >
| > Is there an alternate way of doing a truncate of a table that has a high
| > record count without using "load" and is fast?
| ALTER TABLE T ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE;
| COMMIT;
|
| Cheers
| Serge
|
| --
| Serge Rielau
| DB2 Solutions Development
| IBM Toronto Lab
Feb 16 '06 #9
th_maran
4 New Member
dear Sumanth

To Truncate a table in db2 i am using the below method

Unix: IMPORT FROM /dev/null OF DEL REPLACE INTO <table>
Windows: IMPORT FROM A.IXF OF IXF REPLACE INTO <table>
(just create an empty .ixf file)

thanks
Thirumaran
Feb 17 '06 #10

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

Similar topics

3
4522
by: martin | last post by:
Hi, We have a heavily used production server and a table which logs every hit on a web site. This table has grown large over time and we want to clear it down as efficiently as possible. We would like to issue a truncate table statement, but with millions of rows we are a bit wary of how this will affect server performance. The alternative is to delete is stages using rowcount but of course this will generate a large amount of logging....
3
8647
by: LineVoltageHalogen | last post by:
Greeting All, I have a stored proc that dynamically truncates all the tables in my databases. I use a cursor and some dynamic sql for this: ...... create cursor Loop through sysobjects and get all table names in my database. .... exec ('truncate table ' + @TableName)
1
3032
by: New MSSQL DBA | last post by:
I have recently been assigned to take over several MSSQL environments and found some of the existing practice confusing. As most of my previous experiences are on Oracle and Unix platform so would like your inputs and comments. 1) TX log truncate: In the existing environment, there are scheduled jobs to truncate transaction log of each database in the server and shrink them back to a desired size, say 1G. These jobs are all scheduled...
5
3102
by: ronin 47th | last post by:
Hi group, In one of the books 'Gurus Guide to Transact SQL' i found this info: ------------------------------------------------------------ TRUNCATE TABLE empties a table without logging row deletions in the transaction log. It can't be used with tables referenced by FOREIGN KEY constraints, and it invalidates the transaction log for the entire database. Once the transaction log has been invalidated, it can't be backed up until the...
2
47720
by: rdraider | last post by:
Hi, I am trying to create a script that deletes transaction tables and leaves master data like customer, vendors, inventory items, etc. How can I use TRUNCATE TABLE with an Exists? My problem is I have 200+ tables, if I simply use a list like: truncate table01 truncate table02 truncate table03 ....
14
12276
by: Sala | last post by:
Hi I want to truncate all data in database ... pls help me how i ll truncate?
10
13878
by: Troels Arvin | last post by:
Hello, Until this date, I believed that DB2 has no TRUNCATE TABLE command. But then I came across http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/c0023297.htm where it says: After an ALTER TABLE statement containing REORG-recommended operations, you can execute only the following statements on a table:
5
1091
by: Timothy Madden | last post by:
Hello I see there is now why to truncate a file (in C or C++) and that I have to use platform-specific functions for truncating files. Anyone knows why ? I mean C/C++ evolved over many years now, and still, people making _the_ standards never decided to include such a function. Even in POSIX it was included only in recent versions, mostly not fully supported yet.
8
7695
by: ananthaisin | last post by:
How to reduce the table size for any table while using truncate or delete statements. In oracle 8i it was truncating the storage space but in 10g it is not .... I have given truncate statement in a procedure to drop the storage of a table used... when its record count exceeds 500. BEGIN i:= 0; FOR CC IN NLD LOOP
0
8063
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
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
8498
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...
1
8152
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,...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
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...
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1331
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.