How to create a copy of a DB2 database table

07 June,2016 by Tom Collins

Question: I’m making a change to DB2 LUW database table – and would like to first backup the table – before I make the change. What is a method for backing up a table and data?

 

Answer: This method will create the table LIKE the source table , and then the INSERT statement will take all the data from the source table and INSERT into the target table.

 

 

CREATE TABLE MYSCHEMA.A_NEW_TBL LIKE MYSCHEMA.AN_OLD_TBL;
INSERT INTO MYSCHEMA.A_NEW_TBL (SELECT * FROM MYSCHEMA.AN_OLD_TBL);

 

Note: Using this method will not copy across all objects associated with this table. The LIKE method copies the implicit definition of the table. The implicit definition does not include unique constraints, foreign key constraints, triggers, or indexes.

To get full details of all the options available for the CREATE TABLE .. LIKE option have a read through the documentation.

As an alternative method, which gives you greater control you can look at the process to  create a DDL on an existing DB2 table (DBA DB2)

Read More on DB2 Object management

Extract DB2 create database ddl using db2look and -createdb switch ...

Compare DDL of 2 databases in DB2 (DBA DB2)

 

Author: Rambler(http://www.dba-db2.com)

Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to create a copy of a DB2 database table

Comments are moderated, and will not appear until the author has approved them.


dba-db2.com | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright