Solved

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

Posted on 2010-09-16
7
1,378 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
[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
  • 2
7 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen 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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 45

Expert Comment

by:Kent Olsen
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:Kent Olsen
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

Suggested Solutions

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…

739 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