SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Dealing with FK in DTS copying?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eagle_f90
Constraint Violating Yak Guru

USA
424 Posts

Posted - 05/25/2013 :  19:55:21  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
I am trying to use the SQL Server Import and Export Wizard to copy data from my production db to my dev db but when I do it fails with the error "The INSERT statment conflicted with the FOREIGN KEY constraint" i have over 40 tables with lots of FK constraints, is there some way to deal with this without having to write a drop constraint/add constrat script?

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

MuMu88
Aged Yak Warrior

547 Posts

Posted - 05/25/2013 :  20:20:54  Show Profile  Reply with Quote
You can disable foreign key constraint and enable it after insert operation.
Follow this link:
http://msdn.microsoft.com/en-us/library/10cetyt6(v=vs.80).aspx
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

USA
424 Posts

Posted - 05/25/2013 :  21:20:09  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
quote:
Originally posted by MuMu88

You can disable foreign key constraint and enable it after insert operation.
Follow this link:
http://msdn.microsoft.com/en-us/library/10cetyt6(v=vs.80).aspx



That is even more work then scripting a drop/add constraint file plus it requires Visual Studio. I am looking for an efficent SQL Server solution.

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 05/26/2013 :  00:20:50  Show Profile  Visit russell's Homepage  Reply with Quote
Either you need to serialize the data imports and have them in the proper order, or...

You can easily disable all constraints like this:
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'


Then import your data, before enabling all constraints:
EXEC sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all'

Edited by - russell on 05/26/2013 00:21:19
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

USA
424 Posts

Posted - 05/26/2013 :  10:37:28  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
That worked thanks perfectly!

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 05/26/2013 :  11:15:51  Show Profile  Visit russell's Homepage  Reply with Quote
Welcome. Glad it worked for you.
Go to Top of Page

zkwaywow
Starting Member

3 Posts

Posted - 06/04/2013 :  04:46:15  Show Profile  Reply with Quote
That's great,I agree with your thought.

__________________
Living without an aim is like sailing without a compass.
unspammed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000