I'll be writing a script, where given a col name, I need to determine the name of the default constraint (if any) that exists on it, and delete it. At present, I am using the foll query to determine the constraint name:
select t_obj.name as TABLE_NAME
,c_obj.name as CONSTRAINT_NAME
,col.name as COLUMN_NAME
join sysobjects t_obj on c_obj.parent_obj = t_obj.id
join sysconstraints con on c_obj.id = con.constid
join syscolumns col on t_obj.id = col.id and con.colid = col.colid
where t_obj.name = '<table name>'
and c_obj.xtype = 'D'
and col.name = '<column name>'
if i was running this manually from the query analyzer, then what i could do is, run it, then see which constraints are returned, and then maybe run another "ALTER TABLE DROP CONSTRAINT" query ... but from a script, i cant do that since i dont know the name of the constraint unless i "look" at the results returned
can anyone help me?