on 2018 Sep 19 12:48 PM
I am trying to unload a DB into files using DBUNLOAD, and then load/input the resulted tables(.dat files) into an empty DB. I have problem in inputing these tables because of not respecting the order of relationships between tables. Example: a table containing a foreign key is trying to be loaded before the corresponding table with primary key being loaded!! How should I tell the DBUNLOAD to respect the relationships of tables? I didnt find any such option in the documentation. As a workaround I have used SET OPTION WAIT_FOR_COMMIT='ON', but this makes the load process much more slower. Anyone could help?
Request clarification before answering.
> As a workaround I have used SET OPTION WAIT_FOR_COMMIT='ON', but this makes the load process much more slower.
If memory serves, running ALTER TABLE DROP FOREIGN KEY for all the foreign keys before loading the data, then ALTER TABLE ADD FOREIGN KEY again AFTER loading the data, runs pretty well.
...just the foreign key definitions, not the primary keys... that's a different discussion 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply, this could be the solution, but the question is, is there a way to read all the configurations of FOREIGN KEYS so that I can read them again after dropping? OR, I should drop all FOREIGN KEYS on a table and then add them (and repeat this for each table having FK)? Could I use the SYSCONSTRAINT for example?
I would simply let Dbunload -n create the reload.sql. This includes a section with all FK declarations (as John has mentioned), so you can just use that section.
dbunload creates a reload script that defines the tables with their primary keys, then loads the data, then does ALTERs to add the foreign keys. It shouldn't be possible to get key violations during the data loads.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A full unload without the -d would generate the other statements I'm talking about. In the general case, there is not always an ordering of data loads that will work so dbunload does work that way. If you happen to have a schema for which there is an ordering of LOADs which will work, you will need to order the data loads yourself according to your schema. Alternatively, if it is possible in your case, your 'empty' database should not have the schema either: let dbunload generate the schema definitions for you too.
User | Count |
---|---|
75 | |
30 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.