Solved

How to Truncate Table in DB2 and creating empty table

Posted on 2007-04-02
4
5,601 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:Kent Olsen
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

820 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