Loading ...

SQL Server: Get list of all constraints | CodeAsp.Net

SQL Server: Get list of all constraints

 /5
0 (0votes)

Below is the SQL query to get all constraints:

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

Below is the output when I ran the same query on msdb database:

Comments (no comments yet)

Top Posts