Solved

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

Posted on 2010-09-16
7
1,311 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now