How to get list of all Check Constraints in SQL Server Database - SQL Server / TSQL Tutorial Part 85

Scenario:

You are working as SQL Server developer, you need to provide the query that should return list of all the Check Constraint in SQL Server database.

Solution:

We can use different system objects to get this information.

--List Check Constraints in Database
SELECT DB_Name() AS DBName
    ,Schema_Name(Schema_id) AS TableSchema
    ,Object_name(parent_object_id) AS TableName
    ,o.NAME AS ConstraintName
FROM sys.objects o
WHERE type_desc = 'CHECK_CONSTRAINT'


How to get list of Check Constraints in SQL Server Database


If you are interested to get definition of Check Constraints with table name, you can use below query.


--Get Check Constraints in Database with Definition
SELECT DB_Name() AS DBName
    ,Schema_Name(Schema_id) AS TableSchema
    ,Object_name(parent_object_id) AS TableName
    ,DEFINITION
FROM sys.check_constraints



How to get list of Check Constraints with definition in SQL Server Database



Video Demo : How to get list of all Check Constraints in SQL Server Database