如何获取检查规则约束

时间:2015-05-13 22:17:10

标签: sql sql-server tsql

如何获得检查约束的表达式

使用MSSMS,我可以很容易地看到表Person有一个名为CHECK constraint的{​​{1}}验证表达式CK_Person

通过此查询,我可以获得([DateOfBirth]<[DateOfDeath])COLUMN_NAMECONSTRAINT_NAME

CONSTRAINT_TYPE

所得

SELECT CCU.COLUMN_NAME, CCU.CONSTRAINT_NAME,  TC.CONSTRAINT_TYPE
    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC
    INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS CCU ON TC.CONSTRAINT_NAME = CCU.CONSTRAINT_NAME
    WHERE TC.TABLE_NAME = 'Person'

但我怎样才能获得实际的表达呢?

1 个答案:

答案 0 :(得分:3)

试试这个......

SELECT definition AS Check_Expression
      ,name       AS ConstraintName
FROM sys.check_constraints
WHERE Parent_object_ID = OBJECT_ID('TableName')