tags:

views:

73

answers:

4

I have two database one with relationship(no data) and another with out Relationship (with data) and i want to insert data from one database to another database i am not able import data i got the error for forgien key.

Is there any way for this ?

+1  A: 

Assuming that your data relates properly, you will need to insert your data in the right order, parent then child.

If it doesn't relate, then when you are extracting the data you need to select only the data that will relate properly.

If you don't care about the relationships then it's possible to drop the relationships... but that would go against the whole "relational database" thing.

Iain Hoult
+2  A: 

You need to copy the data over in the correct order, starting with data at the bottom of the "tree".

e.g. TableA, TableB, TableC If TableA references a record in TableB which in turn references a record in TableC then you should import the data in this order: 1) TableC 2) TableB 3) TableA

AdaTheDev
A: 

You could disable all the foreign key constraints on the database, import your data and then re-apply the constraints.

Here's away of removing all the constraints

Jon Mitchell
I appreciate this isn't the best way of going about things, but it'll get the job done.
Jon Mitchell
i am currently doing like this ok because no option other process will take time
KuldipMCA
A: 

Try looking into Log Shipping. I am only familiar with it on SQL Server, so hopefully you are using that DB instance. If not, the premise operates off the fact that all changes to a database are (nearly) always included in the db logs. If you ship those logs to another database and have it run through them (in order), the second database should now be in the same state as the first.

Ty