mass import FOREIGN KEY same table

57 views Asked by At

I have scripted data from a database and want to import them to another, however, I'm getting a FOREIGN KEY SAME TABLE error. After looking at the data I've noticed that FK the row is expecting is created couple of insert statements below. Is there a way to execute the script without having to manually change the order of insert statements?

NOTE: I am using dacpac publish from sqlproj (SDK)

1

There are 1 answers

0
Branislav B. On BEST ANSWER

Disable the constraint check first

ALTER TABLE dbo.myTable NOCHECK CONSTRAINT FK_myTable_myTable GO

then enable it using

ALTER TABLE dbo.myTable CHECK CONSTRAINT FK_myTable_myTable GO