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
809 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FTP on FreeBSD server 2 111
Linux :how to provide sudo access to the user 13 88
Unix How to Bulk Remove Multiple Directories from FileSystem 10 76
SQL400 max size 5 75
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

932 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

11 Experts available now in Live!

Get 1:1 Help Now