Sunday, 15 September 2013

sql server 2008 - INSERT statement conflicted with the FOREIGN KEY constraint Import Data -



sql server 2008 - INSERT statement conflicted with the FOREIGN KEY constraint Import Data -

i importing info 1 database database same table construction using task - import data . getting error insert statement conflicted foreign key constraint . want when import info not error . . possible delete foreign key table , after import run script foreign key table , if yes how can . reply , comments

i suggest importing raw info staging table, has no fk constraints. there, can query staging area, , determine values violating fk constraints.

ex. create table called tblimport, , fk on field city. city table has new york , los angeles, when select distinct city tblimport see las vegas there. las vegas violating constraint. can add together las vegas city table, , import out violating fk constraint.

once have imported final destination, drop tblimport.

i should add, cannot drop fk, import, re-add fk. operation re-add fk check constraint, , fail.

you need either 1) add together relationship entry allows import suggested above or 2) write import script satisfies constraints of fk, , imports records relationship exists (ie. import new york , los angeles).

sql-server-2008

No comments:

Post a Comment