Tuesday, May 31, 2011

Simplified Method to Export and Import Data from/to DB2 tables

Here is an easy way to export and import data from and into a DB2 Table.

-- EXPORT

1. Create a sql file (export.sql) with following content.
--
connect to db2Instance user username using password;
Export to /filepath/tableDataFile.dat of del modified by nochardel coldelx09
select * from schema.tableName with ur;
Connect reset;
terminate;
--

2. Execute the sql file like this:

db2 -tvf export.sql &



-- IMPORT

1. Create a sql file (import.sql) with following content.
--
CONNECT to db2Instance  user username using password;

LOAD CLIENT FROM '/filepath/tableDataFile.dat' OF DEL MODIFIED BY NOCHARDEL COLDELX09 MESSAGES '/filespath/tableDataFile.msg'
TEMPFILES PATH /tempfilespath  INSERT INTO schema.tableName NONRECOVERABLE INDEXING MODE REBUILD;

RUNSTATS ON TABLE schema.tableName WITH DISTRIBUTION AND INDEXES ALL ALLOW WRITE ACCESS;
CONNECT Reset;
TERMINATE;
--
2. Execute the sql file like this:
db2 -tvf import.sql &

No comments:

Post a Comment