Sql-Server
在 SQL Server 中禁用查找約束
我正在審計 SQL Server 中的約束。
如何找到所有未啟用的約束?
這在使用下一個聲明之後:
alter table mytable nocheck constraint all
為此使用系統視圖:
select * from sys.check_constraints where is_disabled = 1;
SELECT [object] = QUOTENAME(s.name) + N'.' + QUOTENAME(t.name), [disabled_constraint] = c.name FROM sys.tables AS t INNER JOIN sys.schemas AS s ON t.schema_id = s.schema_id INNER JOIN sys.check_constraints AS c ON t.object_id = c.parent_object_id WHERE c.is_disabled = 1;