[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to Truncate Table in DB2 and creating empty table

Posted on 2007-04-02
4
Medium Priority
?
5,886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 46

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 2000 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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
What we learned in Webroot's webinar on multi-vector protection.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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