Hi Folks,
Hope you are doing fine!
Today, I will share a simple T-SQL script to find the list of CHECK CONSTRAINTS defined and associated with the database objects within a particular database. Please find below the T-SQl script for your reference:
T-SQL Script:
USE [Northwind]
GO
/* T-SQL to find the list of all CHECK CONSTRAINTS
associated with the objects within a particular database... */
SELECT
o.type_desc AS ObjectType,
'[' + SCHEMA_NAME(o.schema_id) + '].[' + o.name + ']'
AS ObjectName,
ISNULL(clmn.name, '') AS ColumnName,
'[' + SCHEMA_NAME(c.schema_id) + '].[' + c.name + ']'
AS CheckConstraintName,
c.definition AS CheckCondition,
c.is_system_named AS IsSystemDefinedName,
c.is_not_trusted AS IsNotTrustedCheckConstraint,
c.is_disabled AS IsDisabledCheckConstraint,
c.create_date,
c.modify_date
FROM
sys.check_constraints AS c
INNER JOIN sys.objects AS o ON c.parent_object_id = o.object_id
LEFT JOIN sys.columns AS clmn ON c.parent_object_id = clmn.object_id
AND c.parent_column_id = clmn.column_id
ORDER BY
ObjectName, CheckConstraintName, ColumnName
GO
Snap-shot:
Originally posted here at my primary WordPress blog!
Hope, this may help you somewhere...!
Happy Coding :-)
No comments:
Post a Comment