Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can you migrate identity column-based DB2 UDB Tables(v8.x) to another UDB DB version without impacting RI tables based on the identity column?

Posted on 2008-10-11
5
Medium Priority
?
822 Views
Last Modified: 2008-10-18
Hi all,
I have a question regarding database migration. For illustration purposes, I have a DB table and a dependent table such as:
Table 1: Employee:
              column EMPLID     INTEGER generated always   (Primary Key)
               column ...
Table 2: Address
              column: ADDRID     INTEGER  (FK = Foreign key to Employee table)
              column: ...
Changes in business rules require that I add some additional columns and also to remove (retire) some existing columns in the Employee table, drop and recreate the Employee table while preserving existing data and Parent-Child relationships. My question is:

What are my options in migrating this table with all the changes required while preserving the existing identity column and the RIs?  Any issues or concerns that you may have or foresee?

Any and all responses will be appreciated...

Thanks

0
Comment
Question by:Enuda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22693187
well,
you have 2 options:
keep using your table - add the new columns and ignore the old ones
if you want to recreate the table you will have to first drop all the foreign key, unload data from the table, drop and recreate and then load the data back and create the foreign keys again
when you load the data into the table, change the identity column to be generated by default (not generated always)
this way db2 will allow you to insert the old values and your integrity will be kept
0
 

Author Comment

by:Enuda
ID: 22693385
Ok, momi_sabag,
Your suggestion will work just fine as long as I am adding new columns (with default values, of course) at the end of the table structures and then reloading, etc etc.

But I want to add new columns and take out some other columns. For example, I have original 25 columns, I drop ten old columns including whatever data that it holds (if you can imagine that!), and then proceed to add 5 new columns that never existed before. But none of this changes affect the primary or foreign keys, okay? This means the primary table no longer looks like the original. It is for all intent and purpose a "NEW" table because of this changes. So now I want to load the "NEW" table with the old data offloaded earlier in the process...while preserving the RI.

I understand how to preserve the identity column values but how do you reload the data to changed table structure when some columns will no longer exist? Export-Import will fail so also will doing a load with original columns in place.
Any tool or script to do this? My idea is to offload (export DEL or IXF) data by doing a select on the columns I want to keep from the table. Follow your suggestion and reload dat after adding the new columns with defaults and then recreate the foreign keys...do you see any holes or concern with this?

Thanks
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22693692
the easiest thing to do would be :
create the new table with the new structure with some dummy name for example new_table
perform
insert into new_table
select .... from old_table

once you have all the data in the new table, drop the old table and rename the new table to have the old table name
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 1000 total points
ID: 22693694
don't forget to create all the indexes (views etc..) and give all permissions after you do the above
0
 

Author Comment

by:Enuda
ID: 22749949
insert into new_table
select .... from old_table

I am concerned about logging for a very large table...TBs of data.

Will  "NOT LOGGED INITIALY" do the trick for insert also?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question