Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Display all constraints of table?

You can display all constraints available on database table using sys.objects, or INFORMATION_SCHEMA.

Example:

Following query returns all constraints from user table using sys.objects.
-- To Display all the Constraints in table ‘aspnet_Users’
SELECT OBJECT_NAME(object_id) AS ConstraintName,
SCHEMA_NAME(schema_id) AS SchemaName,type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT' AND OBJECT_NAME(parent_object_id)='aspnet_Users'

 

Following query returns all constraints from user table using INFORMATION_SCHEMA.
-- To Display all the Constraints in table ‘aspnet_Users’
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME='aspnet_Users'


Output:


Invalid entry,please enter valid data.

Loading