Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 825
  • Last Modified:

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?

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
Enuda
Asked:
Enuda
  • 3
  • 2
1 Solution
 
momi_sabagCommented:
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
 
EnudaAuthor Commented:
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
 
momi_sabagCommented:
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
 
momi_sabagCommented:
don't forget to create all the indexes (views etc..) and give all permissions after you do the above
0
 
EnudaAuthor Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now