Link to home
Start Free TrialLog in
Avatar of kumarjeevan
kumarjeevan

asked on

How to Truncate Table in DB2 and creating empty table

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
Avatar of elfe69
elfe69
Flag of Switzerland image

Delete and create the table again, use:

DROP TABLE schema.tablename;
CREATE TABLE schema.tablename (...);
Avatar of kumarjeevan
kumarjeevan

ASKER

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
Avatar of Kent Olsen
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
ASKER CERTIFIED SOLUTION
Avatar of elfe69
elfe69
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial