Click here to Skip to main content
13,048,805 members (85,698 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,
As i need to know the database Foreign keys & Primary keys list due to i need to insert from database1 to database2 at that time i need to drop the Foreign keys, Primary keys off the database2 so that i can insert the Data's of database1 after that i need to recreate the keys

Note : i got the query for foreign keys list but when i try to drop Foreign keys at that time i getting primary key reference error

thanking you for your help soon!!
Posted 23-Apr-12 19:15pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Who suggested/asked you to do the migration this way? Do you have any idea on how much data issues can be introduced this way? There was/is a reason why Primary key & Foreign keys are defined. I would not suggest you to do this way at all.

Instead try:
1. Have a look at the database design properly. make a list of tables in a sequence where the lowest tables having maximum dependencies and top once being kind of master table with only primary keys.
2. Populate/Migrate the table from top to bottom order - First the master tables and then the dependent tables.

This way you wont need to drop any key and the data would have least chance of getting corrupt.

I would suggest you to talk to your senior and get more guidance in case you need more help on the same.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It is generally a bad idea to do this, but sometimes you need to do it for bulk inserts.

You can disable constraint checking, see here :[^]
AZAD88 24-Apr-12 4:21am
Thanks for u r comments i have already analysis issues & i have explained too but no use here i am in freak situation that y i posted with a hope !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100