views:

15

answers:

1

I have the SQL query for getting all the constraint names, but not sure how to get its status like whether it is enabled/disabled?

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

Any help?

+2  A: 

Use OBJECTPROPERTY(OBJECT_ID('FK_foo_bar', 'CnstIsDisabled')

OR

Use sys.foreign_keys which has a column "is_disabled"

gbn
+1 I didn't find the `CnstIsDisabled` object property, but sys.foreign_keys worked. I went hunting around INFORMATION_SCHEMA but didn't find any flag here.
mdma
@mdma: are you Antoops who asked the question too?
gbn
@gbn - no, but I was interested in the answer. (I also started researching the answer.)
mdma