如何获得检查约束的表达式?
使用MSSMS,我可以很容易地看到表Person
有一个名为CHECK constraint
的{{1}}验证表达式CK_Person
。
通过此查询,我可以获得([DateOfBirth]<[DateOfDeath])
,COLUMN_NAME
和CONSTRAINT_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'
但我怎样才能获得实际的表达呢?
答案 0 :(得分:3)
试试这个......
SELECT definition AS Check_Expression
,name AS ConstraintName
FROM sys.check_constraints
WHERE Parent_object_ID = OBJECT_ID('TableName')