如何检索外键约束的状态?

时间:2010-07-29 09:58:10

标签: sql foreign-key-relationship

我有获取所有约束名称的SQL查询,但不确定如何获取其状态,如是否启用/禁用?

SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint, 
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType,*
FROM sys.objects

任何帮助?

1 个答案:

答案 0 :(得分:2)

使用OBJECTPROPERTY(OBJECT_ID('FK_foo_bar', 'CnstIsDisabled')

OR

使用包含“is_disabled”列

sys.foreign_keys