If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > db2 Database ddl and data export

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-12, 15:20
junaid377 junaid377 is offline
Registered User
 
Join Date: Jan 2012
Posts: 40
db2 Database ddl and data export

Hi all,

I have a database named test on a redhat linux 6.1 enviroment. I need a command to generate the whole DDL of the database. Everything ranging from tables, views, privileges, procedures, triggers, constraints, referential integrity.

Is it possible and if so what will be the command. I know it will use dblook but I have been unable to run it.Also I need to know will this command create DDL of all the tables including the Syscat tables and tablesspaces?

And how will I use it to create the database on the other instance. Will I first manually create a database and then use this ddl or will it automatically create a Database.

Also I need to export all the data of the database. Basically, I need the ddl to create the database in another instance and then use the exported data to populate the newly created database.

I know we can directly export the whole database but I need these perform these 2 steps separately
Reply With Quote
  #2 (permalink)  
Old 01-19-12, 19:25
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Use backup/restore if the source and target platforms are compatible:
IBM DB2 9.7 for Linux, UNIX and Windows Information Center
Reply With Quote
  #3 (permalink)  
Old 01-19-12, 19:34
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
If you cannot use backup and restore, you can use db2look for the DDL and db2move for the data. db2look does not create the database (you need to create that manually). db2look does not create the catalog tables, as these are created when the database is created.

When you use db2look, be sure to specify a different delimiter (see db2look options) such as "@" so that your stored procs will work in the script. It will include the tablespaces if you ask for those, as well as other objects (check the db2look command options).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 01-21-12, 11:35
junaid377 junaid377 is offline
Registered User
 
Join Date: Jan 2012
Posts: 40
Quote:
Originally Posted by Marcus_A View Post
When you use db2look, be sure to specify a different delimiter (see db2look options) such as "@" so that your stored procs will work in the script. It will include the tablespaces if you ask for those, as well as other objects (check the db2look command options).
if i specify another delimiter like % will i have to do anything when i load the sql in another db or will the new db2 recognize the changed delimiter??

I am using db2 -tvf query.sql to load the sql file ?
Reply With Quote
  #5 (permalink)  
Old 01-21-12, 11:56
junaid377 junaid377 is offline
Registered User
 
Join Date: Jan 2012
Posts: 40
When I run the file with the delimiter change it gives the following error

SQLN0007N the character % following end is not valid. SQLSTATE=42601

I am using the following command

db2look -d <database> -e -a -l -m -x -td % -o test.sql

and to load

db2 -tvf test.sql

any solution??
Reply With Quote
  #6 (permalink)  
Old 01-21-12, 12:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
This one works for me:
db2look -d <database> -e -a -l -xd -f -td @ > test.sql
the ">" pipes it to output file name instead of using -o

I would not use % since it could be used as part of a Like Statement in the where clasue of some select.

When you run it on the new database, use this:
db2 -td@ -vf test.sql
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #7 (permalink)  
Old 01-22-12, 10:16
junaid377 junaid377 is offline
Registered User
 
Join Date: Jan 2012
Posts: 40
will this be suitable for transferring a production server from Linux to windows.... and will the transfer be accurate enough to not force any changes to the front end system?
Reply With Quote
  #8 (permalink)  
Old 01-22-12, 10:37
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by junaid377 View Post
will this be suitable for transferring a production server from Linux to windows.... and will the transfer be accurate enough to not force any changes to the front end system?
That depends on the DB2 release you run the export on. Some older releases may have some bugs.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #9 (permalink)  
Old 01-22-12, 13:41
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
You need to modify tablespace definitions in db2look output.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On