Solved

Determine table load order with many foreign keys in to DB2 LUW 9.5

Posted on 2010-09-16
7
1,326 Views
Last Modified: 2012-05-10
Objective: Loading many tables in the correct order to prevent foreign key and any other violations.

We have 60-90 tables that need to be loaded into a DB2 LUW 9.5 instance.  There are a considerable number of foreign key relationships on many tables.

I "think" an SQL script that looks at various system tables, and produces a list of the "load order of tables" is needed. The list can include the type of table (table, view, nickname, etc), and any other information that you believe is useful (number of rows in the tables would be a plus, but certainly not necessary).

I have searched for hints or scripts that might provide this capability.  
 
Notwithstanding RISKS, what about an sql script to disable keys, indices, foreign keys, et cetera prior to loading data?  And a second SQL script to enable all of these subsequent load completion?  Is that possible?

Finally, the only software tools we have available are Control Center and Data Studio 2.2.  A third party ETL tool will be used to select and load the data (not DBLoad).

I may be asking for a lot, so I will make this a 500 point question;  depending on responses I may award points to "best-assisted" answers too.

Please let me know if additional information is needed.
0
Comment
Question by:JdanielII
  • 3
  • 2
  • 2
7 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 33696819
Hi Daniel,

If it were me, I'd disable the foreign keys and load the tables in any order that makes sense to you.

ALTER TABLE mytable ALTER FOREIGN KEY keyname NOT ENFORCED;

Then load the table and reenable the constraint.

ALTER TABLE mytable ALTER FOREIGN KEY keyname ENFORCED;


Not only will this eliminate the need to load the tables in a specific order, it usually results in better performance in the entire load process.  DB2 will check all of the constraints in one pass instead of reading the foreign table with each loaded row.

Dropping the indexes before you load the data will also generally improve performance.

Of course, those rules must be flexible.  If the table already has 1,000,000 rows and you're adding 100, it's probably not a good idea to disable the constraint and drop the indexes.


Kent
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 33697043
so what will it be?
do you need the script or you go with kent's advice?
0
 

Author Comment

by:JdanielII
ID: 33697194
1st choice is a script; my colleagues can also use this info daily.  We may not be able to alter, but I know we can select from sysibm.

Thanks for inquiring.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 45

Expert Comment

by:Kdo
ID: 33697295
Hi Daniel,

Are you loading the tables fully or adding to existing data?

0
 

Author Comment

by:JdanielII
ID: 33697345
Target tables will initially be empty. Only full table loads will be performed.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 33697371
That's certainly the easiest to navigate.  :)

I strongly suggest that you load the tables without indexes or constraints and add them after the loads are complete.  You'll see a huge performance benefit from this approach.

It might take someone with DBA permissions, but that should be easy to arrange.  If you're loading to your own schema, you should have those permissions.


Kent
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 33697380
I have to agree with Kent
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 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

25 Experts available now in Live!

Get 1:1 Help Now