codec
codec

Reputation: 8806

DB2: How to get create table command or script for replicating a table

I have DB2 installed locally where I have a table named INCIDENTS. I can do "db2 describe table INCIDENTS" to list the columns and their types. Is it possible to get a create table query or some script which when run on another server can create a table with the same schema?

Upvotes: 1

Views: 7455

Answers (1)

mao
mao

Reputation: 12267

If you are using Db2 for Linux/Unix/Windows, you can use db2look command line tool which can extract the DDL to a text file, which you can then copy to the other server and run against a database there.

Example:

db2look -d <your database> -z <your schema> -t <your table> -e -o script.sql

-e = Extract DDL statements
-o = Output file

If you are happy to have both the DDL and the data, then you can use the command line to export the contents of the table to an IXF file, which you can then copy to the target server and use IMPORT ... CREATE INTO ... to replicate both the DDL and the data and indexes etc.

Use the Db2 Knowledge Center to find the details.

If you prefer to use GUI tools, IBM Data Studio also lets you extract DDL to a file, as do other tools such as DB-Visualiser etc.

Upvotes: 2

Related Questions