sql - How To get the Check Rule Constraint -
how can expression of check constraint?
with mssms can easly see table person
has check constraint
named ck_person
validating expression ([dateofbirth]<[dateofdeath])
.
with query can column_name
, constraint_name
, constraint_type
:
select ccu.column_name, ccu.constraint_name, tc.constraint_type information_schema.table_constraints tc inner join information_schema.constraint_column_usage ccu on tc.constraint_name = ccu.constraint_name tc.table_name = 'person'
resulting
+-------------+-----------------+-----------------+ | column_name | constraint_name | constraint_type | +-------------+-----------------+-----------------+ | personid | pk_person | primary key | | dateofbirth | ck_person | check | | dateofdeath | ck_person | check | +-------------+-----------------+-----------------+
but how can actual expression itself?
try this...
select definition check_expression ,name constraintname sys.check_constraints parent_object_id = object_id('tablename')
Comments
Post a Comment