2

I have the following table:

EntityId - PK
Label
ParentEntityId - FK

ParentEntityId is joined to EntityId of the same table. now I am having problems importing data to this table using SSIS because of instances where the parent entities haven't been imported yet and so I get a FK constraint violation. I'm probably missing something obvious.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Mel
  • 3,058
  • 4
  • 26
  • 40
  • 1
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Nov 27 '12 at 07:06

1 Answers1

2

You can disable the foreign key prior to loading the data, then re-enable it after loading completes, both using T-SQL.

Eg - to disable - ALTER TABLE yourTableName NOCHECK CONSTRAINT yourConstraintName

To re-enable - ALTER TABLE yourTableName WITH CHECK CHECK CONSTRAINT yourConstraintName

grapefruitmoon
  • 2,988
  • 1
  • 22
  • 26