How does SqlBulkCopy circumnavigate foreign key constraints?

后端 未结 2 1815
情书的邮戳
情书的邮戳 2020-12-30 21:47

I used SqlBulkCopy to insert a collection of rows into a table. I forgot to set an integer value on the rows. The missing column is used to reference another table and this

2条回答
  •  天命终不由人
    2020-12-30 22:28

    how does SqlBulkCopy manage to leave the database in an invalid state?

    It disables foreign keys on the table you are inserting into.

    Yes, this is a horrible default. Be sure to set the option CHECK_CONSTRAINTS (or CheckConstraints for SqlBulkCopy) if you can at all afford it.

    It also by default does not fire triggers which is equally terrible for data consistency. The triggers are there for a reason.

提交回复
热议问题