Wednesday, November 13, 2013

IBM DB2 ..Move/copy Schema tables to different Schema name ...export and Import

Steps are ...

1) Issue "db2look -d <DBNAME> -e -o <outputfile.sql>"

2) In the outputfile.sql file, find and change the schema to your new schema name. You can use UNIX text editor Vi and edit the file by use the following command ":1,$s/<SEARCH>/<REPLACE>/g" to search and replace or use any text editor that you desire.

3) Issue "db2move <dbname> export". This will create several files, including a db2move.lst file, in your current directory.

4) You will also need to edit the generated db2move.lst file and change the schema names to the new desired name.

5) Drop existing user tables (this step is for renaming the schema within the same database)

6) Issue "db2 -tvf outputfile.sql" (this runs the output file generated by the db2look command to recreate the tables with the new schema name)

7) Issue "db2move <dbname> import" (to import the data into the tables.)

C:\Documents and Settings\terget_schema\Desktop\backup\bkp>db2look -d TEST -e -o outputfile.sql
-- USER is:
-- Creating DDL for table(s)
-- Output is sent to file: outputfile.sql

C:\Documents and Settings\terget_schema\Desktop\backup\bkp>db2move DBNAME export -tc
 Source_db

*****  DB2MOVE  *****

Action:      EXPORT

Start time:  Tue Nov 12 18:45:16 2013


Exporting tables created by:  Source_db;

Connecting to database DBNAME ... successful!  Server: DB2 Common Server V8.2.



Disconnecting from database ... successful!

End time:  Tue Nov 12 18:45:20 2013


C:\Documents and Settings\terget_schema\Desktop\backup\bkp>


2) In the outputfile.sql file, find and change the schema to your new schema name. You can use UNIX text editor Vi and edit the file by use the following command ":1,$s/<SEARCH>/<REPLACE>/g" to search and replace or use any text editor that you desire.

3)You will also need to edit the generated db2move.lst file and change the schema names to the new desired name.



4) db2 -tvf outputfile.sql




5 )db2move DBNAME import

C:\Documents and Settings\terget_schema\Desktop\backup\bkp>db2move TEST import

*****  DB2MOVE  *****

Action:      IMPORT

Start time:  Tue Nov 12 18:48:49 2013


Connecting to database TEST ... successful!  Server: DB2 Common Server V8.2.1


Disconnecting from database ... successful!

End time:  Tue Nov 12 18:48:59 2013

No comments:

Post a Comment