Solved

How to Truncate Table in DB2 and creating empty table

Posted on 2007-04-02
4
5,535 Views
Last Modified: 2010-10-05
How to create a emtyp file in DB2, i am trying to truncate the table using load import form /dev/null of del replace schema.tablename, but it keeps saying path not found or no table to read.
Database: DB2
OS: Windows
0
Comment
Question by:kumarjeevan
  • 2
4 Comments
 
LVL 11

Expert Comment

by:elfe69
ID: 18835452
Delete and create the table again, use:

DROP TABLE schema.tablename;
CREATE TABLE schema.tablename (...);
0
 

Author Comment

by:kumarjeevan
ID: 18835638
I dont want to drop and re-create simple delete all rows without logging, in mysql i could use truncate table command, to acheive this, but DB2 does not support this, i read through the solutions here and found out that you could trick DB2 and acheive same benefits as Truncate Table by using load import / replace command, i am unable to use this command because its not able to locate the empty table, please help
0
 
LVL 45

Expert Comment

by:Kdo
ID: 18835654
Hello kumarjeevan,

DROP TABLE / CREATE TABLE in sequence will empty the table very quickly.  If you have other objects tied to the table (like indexes, triggers, views, etc.) this method becomes a lot of work as you'll have to regenerate all of these objects.


If you've got sufficient privilege, the ALTER TABLE statement is perhaps the fastest way to empty the table without affecting the other objects.

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


And of course, you can always use the DELETE command.  This will empty the table, but on modest or large data volumes will be slower than the ALTER TABLE statement above.

DELETE FROM mytable;

If you're going to use this method, it will go faster if you disable logging.

--  Turn off autocommit
ALTER TABLE mytable ACTIVATE NOT LOGGED INITIALLY;
DELETE FROM mytable;
COMMIT;



Good Luck,
Kent
0
 
LVL 11

Accepted Solution

by:
elfe69 earned 500 total points
ID: 18835673
Try replacing /dev/null by nul, which represents the equivalent to /dev/null in Windows, maybe it will be accepted this way:

load import from nul of del replace schema.tablename
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now