bulkinsert 会导致僵尸记录吗?
Can bulkinsert cause zombie records?
我正在使用 Sql Server Bulkinsert 将大量数据从 XML 文件上传到数据库,通过计划作业 运行 在晚上静静地进行。
背景
考虑这个虚拟模型:
+====================+ +====================+
+ INVOICE + + INVOICE LINES +
+====================+ +====================+
+ PK + InvoiceId +-I-┐ + PK + InvoiceLineId +
+ + ... + └IX-+ FK + InvoiceId +
+ + ... + + + ... +
+====================+ +====================+
我的消息来源有望为我提供可靠的数据,但 mistakes/errors 确实发生了。 Invoice Lines
中的 InvoiceId
FK 可能指向 table Invoice
.
中不存在的 InvoiceId
我的问题
Can feeding incorrectly referenced data to Bulkinsert cause zombie records?
一旦再次打开约束,插入它们会导致(可记录的)警告吗?
如果是这样,这些将是人类检测table。我可以创建一个 post-上传清理。上传前检查会非常复杂,如前所述,这不是我的责任。
PS
要特别清楚我对僵尸记录的意思:
Records stored in database that have no reason to exist because they
have a reference towards a dependency, through a foreign key,
in another table that is non-existant.
据我所知,这是一个普遍接受的术语。
是的,如果未指定 CHECK_CONSTRAINTS
选项,它会导致 INVOICE LINES
行引用不存在的 INVOICE
("zombie records",如您所说)[=16] =]
CHECK_CONSTRAINTS Specifies that all constraints on the target table
or view must be checked during the bulk-import operation. Without the
CHECK_CONSTRAINTS option, any CHECK and FOREIGN KEY constraints are
ignored, and after the operation, the constraint on the table is
marked as not-trusted.
https://msdn.microsoft.com/en-us/library/ms188365.aspx
您可以使用 post-load 查询检测坏行
SELECT *
FROM [INVOICE LINES] il
WHERE NOT EXISTS (
SELECT 1 FROM INVOICE i WHERE i.InvoiceId =il.InvoiceId ) ;
我正在使用 Sql Server Bulkinsert 将大量数据从 XML 文件上传到数据库,通过计划作业 运行 在晚上静静地进行。
背景
考虑这个虚拟模型:
+====================+ +====================+
+ INVOICE + + INVOICE LINES +
+====================+ +====================+
+ PK + InvoiceId +-I-┐ + PK + InvoiceLineId +
+ + ... + └IX-+ FK + InvoiceId +
+ + ... + + + ... +
+====================+ +====================+
我的消息来源有望为我提供可靠的数据,但 mistakes/errors 确实发生了。 Invoice Lines
中的 InvoiceId
FK 可能指向 table Invoice
.
InvoiceId
我的问题
Can feeding incorrectly referenced data to Bulkinsert cause zombie records?
一旦再次打开约束,插入它们会导致(可记录的)警告吗?
如果是这样,这些将是人类检测table。我可以创建一个 post-上传清理。上传前检查会非常复杂,如前所述,这不是我的责任。
PS
要特别清楚我对僵尸记录的意思:
Records stored in database that have no reason to exist because they have a reference towards a dependency, through a foreign key, in another table that is non-existant.
据我所知,这是一个普遍接受的术语。
是的,如果未指定 CHECK_CONSTRAINTS
选项,它会导致 INVOICE LINES
行引用不存在的 INVOICE
("zombie records",如您所说)[=16] =]
CHECK_CONSTRAINTS Specifies that all constraints on the target table or view must be checked during the bulk-import operation. Without the CHECK_CONSTRAINTS option, any CHECK and FOREIGN KEY constraints are ignored, and after the operation, the constraint on the table is marked as not-trusted.
https://msdn.microsoft.com/en-us/library/ms188365.aspx
您可以使用 post-load 查询检测坏行
SELECT *
FROM [INVOICE LINES] il
WHERE NOT EXISTS (
SELECT 1 FROM INVOICE i WHERE i.InvoiceId =il.InvoiceId ) ;