Dave
Dave

Reputation: 1775

When/how are Constraints Checked in a SqlBulkCopy w/ Check Constraints enabled?

I am performing several SqlBulkCopy's in a single transaction, I need to be able to roll back easily if anything goes wrong. I'm bulk copying several tables that have foreign keys to each other. I want these constraints checked. I'm copying the parent table first, then the child tables, but I'm receiving foreign key constraint errors. Does SqlBulkCopy include the rows inserted in the transaction when checking constraints?

Upvotes: 2

Views: 3135

Answers (1)

JodyT
JodyT

Reputation: 4412

By default constraints are not checked. Change the options of the SqlBulkCopy to check them during insertion.

Check constraints while data is being inserted. By default, constraints are not checked

Upvotes: 4

Related Questions