Sql Server - Get database constraints of all tables ( default and check constraints) I need to get constraints of all columns, tables in my database result like this :

DatabaseName | SchemaName | TableName | ColumnName | ColumnType | ConstraintName |


-

ConstraintType | Definition | CreateDate


I already used this answer but it shows just TableName, ColumnName, ConstraintName and definition.

Answer that I used:

SELECT 
    TableName = t.Name,
    ColumnName = c.Name,
    dc.Name,
    dc.definition
FROM sys.tables t
INNER JOIN sys.default_constraints dc ON t.object_id = dc.parent_object_id
INNER JOIN sys.columns c ON dc.parent_object_id = c.object_id AND c.column_id = dc.parent_column_id
ORDER BY t.Name


Thank you for your help.
Hope this script includes all you are trying to retrieve.

This script retrieving CHECK and DEFAULT constraints. You can use INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE to retrieve PK &amp; FK columns.

    DECLARE @Constraint TABLE (
        [Database] [nvarchar](128) NULL,
        [Schema Name] [nvarchar](64) NULL,
        [Table Name] [sysname] NOT NULL,
        [Column Name] [nvarchar](128) NULL,
        [Data Type] [nvarchar](64) NULL,
        [Constraint Name] [sysname] NOT NULL,
        [Constraint Type] [varchar](7) NOT NULL,
        [definition] [varchar](512) NULL,
        [Create Date] [datetime] NULL
    )

    insert into @Constraint
    exec sp_MSforeachdb 'use ?
    select db_name() [Database],schema_name(t.schema_id) [Schema Name],t.name [Table Name],ac.name [Column Name],dt.name [Data Type],dc.name [Constraint Name],''Default'' [Constraint Type],dc.definition,dc.create_date [Create Date]
    from
                sys.tables t
    inner join  sys.all_columns ac
    on          t.object_id=ac.object_id
    inner join  sys.types dt
    on          ac.user_type_id=dt.user_type_id
    inner join  sys.default_constraints dc
    on          t.object_id=dc.parent_object_id and ac.column_id=dc.parent_column_id
    where t.type=''U''
    union all
    select db_name() [Database],schema_name(t.schema_id) [Schema Name],t.name [Table Name],ac.name [Column Name],dt.name [Data Type],cc.name [Constraint Name],''Default'' [Constraint Type],cc.definition,cc.create_date [Create Date]
    from
                sys.tables t
    inner join  sys.all_columns ac
    on          t.object_id=ac.object_id
    inner join  sys.types dt
    on          ac.user_type_id=dt.user_type_id
    inner join  sys.check_constraints cc
    on          t.object_id=cc.parent_object_id and ac.column_id=cc.parent_column_id
    where t.type=''U'''

    select * from @Constraint


Note: You can filter the required result by using where condition with select * from @Constraint.
Thanks!