SQL Dump from DB2

21,351

Solution 1

You could use SQquirreL, an SQL Client implemented in Java, to accomplish this. In its "Objects"-Tree you would select all desired tables and select "Scripts > Create Data Script" from the context menu.

Solution 2

What you're looking for is the db2move command. For a particular schema you should use the "sn" switch.

So for example to export the data:

db2move [your_db_name] EXPORT -sn [your_schema_name]

There are many options and switches available for db2move depending on exactly what you want to do.

If db2move is not exactly what you need, you can review the table of Data Movement Options available in DB2.

Solution 3

You could use the EXPORT, and related IMPORT or LOAD commands if the goal is to transfer data back into another DB2 database.

In fact, you can generate the the statements based on metadata from SYSCAT.TABLES

EXPORT

   SELECT 'EXPORT TO /usr/data/SCHEMA/' || TABNAME || '.ixf OF IXF LOBS TO /usr/data/SCHEMA/lbos/ MODIFIED BY LOBSINFILE SELECT * FROM SCHEMA.' || TABNAME || ';'
     FROM SYSCAT.TABLES
    WHERE TABSCHEMA = 'SCHEMA'
 ORDER BY TABNAME

IMPORT

   SELECT 'IMPORT FROM /usr/data/SCHEMA/' || TABNAME || '.ixf OF IXF LOBS FROM /usr/data/SCHEMA/lobs/ MODIFIED BY LOBSINFILE INSERT INTO SCHEMA.' || TABNAME || ';'
     FROM SYSCAT.TABLES
    WHERE TABSCHEMA = 'SCHEMA'
 ORDER BY TABNAME

If you want the actual insert scripts, then you may need to go with a third-party tool (I'm not aware of one provided by DB2, though I could be wrong.)

Solution 4

Db2 Schema with all DDL Backup :

I have use below command it worked for me to export all DDL.

db2look -d CusDb -x -e -z CusSchema -o OutputFile

Syntax : db2look -d DbName -x -e -z SchemaName -o OutputFile_name

Share:
21,351
jrharshath
Author by

jrharshath

Updated on July 23, 2022

Comments

  • jrharshath
    jrharshath almost 2 years

    I'm trying to dump the contents of a particular schema in one IBM DB2 UDB server into an sql text file (much like the mysqldump functionality of mysql).

    I came across db2look, but it only dumps the structure of the schema (only ddl, no dml).

    So how can I get my thing done?

    jrh.

  • Tamas Czinege
    Tamas Czinege about 15 years
    One thing to note that db2move uses PC/IXL as the data container format and does not produce an SQL dump. I'm not sure if the question asker asked for an SQL dump because that's what he's familiar with or because for some reason he needs a real SQL dump with INSERTs. If the latter, db2move won't help him.
  • Michael Sharek
    Michael Sharek about 15 years
    You're correct, doctor...not really sure what op was after so linked to all data movement options for db2
  • jrharshath
    jrharshath about 15 years
    Well, I used Aqua Data Studio to do that.. it worked pretty well, thank you :)
  • egbokul
    egbokul over 13 years
    Nice, except for a sufficiently large dataset which will NOT fit into memory it just isn't an option. Can be used for smaller tables though.