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)
Extract DB2 create database ddl using db2look and -createdb switch ...
Compare DDL of 2 databases in DB2 (DBA DB2)
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |