Checking if Constraint is on

Posted on 2011-11-01
Last Modified: 2012-05-12

how can we check if the constraint has a check or nocheck right now? I could not see it from
SELECT * FROM sys.objects WHERE type_desc LIKE '%CONSTRAINT'
Question by:25112
    LVL 12

    Expert Comment

    SELECT * FROM sys.objects WHERE type='D'

    Open in new window

    LVL 15

    Accepted Solution


    SELECT name, OBJECT_NAME(parent_obj), CASE WHEN OBJECTPROPERTY(ID,'CnstIsDisabled') = 1 THEN 'Disabled' ELSE 'Enabled' END DisableStatus
    FROM sysobjects
    WHERE xtype IN ('c','d','f','uq')
    LVL 5

    Author Comment

    anujnb, that was it. can you spin that on sql 2005 sys.objects?
    LVL 68

    Assisted Solution

    SELECT name, CASE WHEN OBJECTPROPERTY(object_id, 'CnstIsDisabled') THEN ...
    FROM sys.objects
    WHERE type IN ('c', 'd', 'f', 'uq')
    ORDER BY name
    LVL 15

    Assisted Solution


    SELECT name, OBJECT_NAME(parent_object_id) TableName, CASE WHEN OBJECTPROPERTY(OBJECT_ID,'CnstIsDisabled') = 1 THEN 'Disabled' ELSE 'Enabled' END DisableStatus
    FROM sys.objects
    WHERE type IN ('c','d','f','uq')

    sysobjects will be removed in future versions of sql server, so as you guessed sys.objects is the right choice.

    LVL 5

    Author Comment

    thank you.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Viewers will learn how the fundamental information of how to create a table.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now