views:

47

answers:

3

Is there a TSQL script that will allow me to see the contents of a constraint. I found a question regarding Oracle but I need a TSQL script.

http://stackoverflow.com/questions/2686353/how-to-see-contents-of-check-constraint-on-oracle

I am aware of sys.check_constraints, however, the 'definition' comes back null for all objects.

Select * from sys.check_constraints
A: 
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
Hal
Unfortunately, that doesnt tell give me the content of the constraint only the relationship to the table.
Shiftbit
Have you tried the GUI then?
Hal
No access to management studio, remote access only.
Shiftbit
+2  A: 

Another way

for check constraints

select definition,name
 from sys.check_constraints

for default constraints

select definition,name
 from sys.default_constraints

and yet another way

 SELECT object_definition(OBJECT_ID(CONSTRAINT_NAME)),* 
 FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
 where CONSTRAINT_TYPE <> 'PRIMARY KEY'
SQLMenace
Why does the definition return null? It returns null for every table in the database.
Shiftbit
works for me...what version of sql server are you on?
SQLMenace
Sql Server 2005
Shiftbit
Might be a permission issue, if your login doesn't have sufficient privileges you won't see it
SQLMenace
@SQLMenace It was a permission issue. Unfortunately, I'll have to bug the DBA everytime I encounter constraint errors.
Shiftbit
+1  A: 

To have any check constraints, you're going to need objects of this type.

select *
from sys.objects
where sys.objects.type = 'C'

check_constraints

Jeff O