Friday, September 9, 2011

How to get the Table Name on which the Check Constraint is defined


You can use the following code block to get the information for a given check constraint

DECLARE @ConstraintName varchar(130)
SET @ConstraintName = 'CK_ProductReview_Rating'

SELECT  t.name as TableName,
            c.name as CheckConstraintName,
            c.definition as ConstraintDefinition
FROM  sys.objects t,
            sys.check_constraints c
WHERE c.parent_object_id = t.object_id
AND         c.name = @ConstraintName

No comments:

Post a Comment