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 2005 Forums
 Transact-SQL (2005)
 Can't Drop Column that has a default

Author  Topic 

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-13 : 09:43:49
I did this...

ALTER TABLE tm_spn_equip_def ADD Customer_No int NOT NULL DEFAULT dbo.f_spn_GetCustomerNo() WITH VALUES


Now when I attempt to do this...

ALTER TABLE tm_spn_equip_def DROP COLUMN Customer_No 


I get an error:

Msg 5074, Level 16, State 1, Line 1
The object 'DF__tm_spn_eq__Custo__019E3B86' is dependent on column 'Customer_No'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN Customer_No failed because one or more objects access this column.


How can I get around this?

TIA!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-13 : 10:19:24
You need to drop the constraint before dropping the column

Madhivanan

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

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-13 : 10:39:48
How do I know the name of the constraint that is generated by a default column?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-13 : 11:20:25
As the error message says constraint name is 'DF__tm_spn_eq__Custo__019E3B86'

If you want to drop without knowing the name, try
http://msmvps.com/blogs/robfarley/archive/2007/11/26/two-ways-to-find-drop-a-default-constraint-without-knowing-its-name.aspx

Madhivanan

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

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-13 : 13:49:40
Thanks!
Go to Top of Page
   

- Advertisement -