Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dropping a column

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-06-29 : 00:55:38
Hi friends
am droppping a column thru sql stmt and am getting following error

The object 'DF__s_datavie__Overr__1DA648AE' is dependent on column 'OverrideCol'.
ALTER TABLE DROP COLUMN OverrideCol failed because one or more objects access this column.

bcoz i've a default constraint on this column
my question is, how can i get list of default constraints on this column so that i can drop them first before dropping column. as you'll know that the constraint name can be different on each server having this table so i need to do this.
Thanks for the ideas.


Cheers

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-29 : 01:00:54
use

select object_name(cdefault) as Default_Constraint
from syscolumns
where id = object_id('table_name')
and name = 'column_name'



KH

Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-06-29 : 01:12:05
Thank you very much "kh "
that worked beautifully.

Cheers
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-29 : 01:18:01
You might also want to check for CHECK CONSTRAINTS before dropping the column


KH

Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-06-29 : 01:29:14
thanks KH.
in this case i dont . so i should be fine.
Thanks for ur help.

Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-29 : 01:50:07
SELECT cols.name as column_name, c_obj.name as constraint_name,t_obj.name as table_name
FROM sysobjects t_obj, sysobjects c_obj, syscolumns cols
WHERE cols.id = t_obj.id AND c_obj.id = cols.cdefault AND c_obj.xtype = 'D'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -