SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dropping a column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 06/29/2006 :  00:55:38  Show Profile  Reply with Quote
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)

Singapore
17438 Posts

Posted - 06/29/2006 :  01:00:54  Show Profile  Reply with Quote
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 - 06/29/2006 :  01:12:05  Show Profile  Reply with Quote
Thank you very much "kh "
that worked beautifully.

Cheers
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17438 Posts

Posted - 06/29/2006 :  01:18:01  Show Profile  Reply with Quote
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 - 06/29/2006 :  01:29:14  Show Profile  Reply with Quote
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

India
22713 Posts

Posted - 06/29/2006 :  01:50:07  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000