Link to home
Start Free TrialLog in
Avatar of 25112
25112

asked on

pick only DEFAULT constraints from sysconstraints

how can you filter only the DF constraints from the below:?
 SELECT object_name(constid),object_name(id),COL_NAME(id,colid) FROM sysconstraints
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Is this just for SQL Server 2000?  I ask because you have posted to SQL Server 2008, yet you are using the deprecated SQL Server 2000 System table.
In any case if you still need to use that old table, in order to get the DEFAULT constraints all you have to do is add the following WHERE clause:
WHERE status & 5 = 5
Avatar of 25112
25112

ASKER

thanks- that helped.

i chose sysconstraints because it was neutral to all environments...

for 2008, i came up with
select name,OBJECT_NAME(parent_object_id) ,*  from sys.all_objects where type = 'd'

but i am not able to pull the column name.. can you advise?
but i am not able to pull the column name.. can you advise?
For which version SQL Server 2000 or 2008? The answer should be different in each case.
Assuming you are still using SQL Server 2000, then this is how you would have to do it:
SELECT  o.name, c.name, oc.name
FROM    sysobjects o
	INNER JOIN syscolumns c ON o.id = c.id
	INNER JOIN sysconstraints ct ON o.id = ct.id AND c.colid = ct.colid
	INNER JOIN sysobjects oc ON ct.constid = oc.id
WHERE	o.xtype = 'U'
	AND ct.status & 5  = 5

Open in new window

Avatar of 25112

ASKER

acperkins- thanks for that. sorry i should have kept the intended zone more clear..

can you kindly give me the syntax for 2008 to get column name? appreciate that.
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial