gpt4 book ai didi

sql - 外键列允许 SQL Server 中的 0 进行批量插入

转载 作者:行者123 更新时间:2023-12-03 02:52:36 24 4
gpt4 key购买 nike

我有一列检查列上的 FK 约束并允许 NULL。但是,即使主表中没有 ID 为 0 的行,它也允许 0 作为值。

此插入发生在使用 .NET 进行批量插入时。但是,如果我在 SQL Server 中直接将该值更改为有效数字并返回到 0,那么它将不允许这样做。

所以不知何故批量插入允许允许 0,有什么原因吗?

最佳答案

默认情况下,BULK INSERT 忽略检查和外键约束。您可以使用 CHECK_CONSTRAINTS 打开它们。

文档中对此进行了解释:

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.

关于sql - 外键列允许 SQL Server 中的 0 进行批量插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49526719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com