SQL Server约束“不受信任”

时间:2022-04-10 04:58:55

I recently heard the term “not trusted”:

我最近听说“不信任”这个词:

SQL Server will mark the constraint as “not trusted”.

SQL Server将约束标记为“不受信任”。

Does anyone can explain a bit what is the meaning of that? I know the question is a bit vague but I was wondering if this is a Microsoft specific "term" or is also used by other relational databases?

有人能解释一下这是什么意思吗?我知道这个问题有点模糊,但我想知道这是微软特有的“术语”,还是其他关系数据库也在使用?

2 个解决方案

#1


3  

If you disable a constraint and then enable it again without specifying the WITH CHECK option then SQL Server will mark that constraint as "not trusted" since it can no longer rely on the existence of the constraint to guarantee that the data is consistent with the constraint conditions. This results in the constraint being ignored for the purposes of execution plans, so the best practice is to always use WITH CHECK when re-enabling constraints.

如果禁用约束,然后在不指定WITH CHECK选项的情况下重新启用它,那么SQL Server将将该约束标记为“不受信任”,因为它不再依赖约束的存在来保证数据与约束条件一致。这导致在执行计划的目的中忽略了约束,所以最好的做法是在重新启用约束时使用检查。

#2


0  

Everytime MSSQL cannot check the constraint:

每次MSSQL无法检查约束:

  1. If you disable a constraint and enable without check:
    • Alter table nocheck constraint constraintname
    • 修改表nocheck约束约束约束
    • Alter table with nocheck check constraint constraintname
    • 用nocheck约束约束约束约束约束约束来修改表
  2. 如果您禁用一个约束并启用不检查:用nocheck检查约束约束约束约束约束约束修改表nocheck约束约束约束约束限制
  3. If you create a constraint disables:
    • Alter table with nocheck add constraint ...
    • 使用nocheck添加约束修改表…
  4. 如果创建一个约束禁用:用nocheck添加约束修改表…
  5. If you enable a constraint but there are rows that violates the constraint
  6. 如果启用了约束,但存在违反约束的行

Too see rows that violates the constraint you can use DBCC CHECKCONSTRAINTS

也可以查看违反约束的行,可以使用DBCC检查约束

#1


3  

If you disable a constraint and then enable it again without specifying the WITH CHECK option then SQL Server will mark that constraint as "not trusted" since it can no longer rely on the existence of the constraint to guarantee that the data is consistent with the constraint conditions. This results in the constraint being ignored for the purposes of execution plans, so the best practice is to always use WITH CHECK when re-enabling constraints.

如果禁用约束,然后在不指定WITH CHECK选项的情况下重新启用它,那么SQL Server将将该约束标记为“不受信任”,因为它不再依赖约束的存在来保证数据与约束条件一致。这导致在执行计划的目的中忽略了约束,所以最好的做法是在重新启用约束时使用检查。

#2


0  

Everytime MSSQL cannot check the constraint:

每次MSSQL无法检查约束:

  1. If you disable a constraint and enable without check:
    • Alter table nocheck constraint constraintname
    • 修改表nocheck约束约束约束
    • Alter table with nocheck check constraint constraintname
    • 用nocheck约束约束约束约束约束约束来修改表
  2. 如果您禁用一个约束并启用不检查:用nocheck检查约束约束约束约束约束约束修改表nocheck约束约束约束约束限制
  3. If you create a constraint disables:
    • Alter table with nocheck add constraint ...
    • 使用nocheck添加约束修改表…
  4. 如果创建一个约束禁用:用nocheck添加约束修改表…
  5. If you enable a constraint but there are rows that violates the constraint
  6. 如果启用了约束,但存在违反约束的行

Too see rows that violates the constraint you can use DBCC CHECKCONSTRAINTS

也可以查看违反约束的行,可以使用DBCC检查约束