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
807 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
  • 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 250 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now