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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 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…

622 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