How do I get constraints on a SQL table column

Easiest and quickest way is to use:

sp_help 'TableName'

This query should show you all the constraints on a table:

select chk.definition
from sys.check_constraints chk
inner join sys.columns col
    on chk.parent_object_id = col.object_id
inner join sys.tables st
    on chk.parent_object_id = st.object_id
where 
st.name = 'Tablename'
and col.column_id = chk.parent_column_id

can replace the select statement with this:

select substring(chk.Definition,2,3),substring(chk.Definition,9,6),substring(chk.Definition,20,5) 

You can use

sp_helpconstraint 'tableName', 'nomsg'

to get all the constraints for the table.

"sp_help" return far more information.

Tags:

Sql

Sql Server