views:

427

answers:

2

The error message I'm obtaining when trying to drop a column:

The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.

Msg 5074, Level 16, State 1, Line 43

ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.

I have already tried to find the default constraints, as described here: http://stackoverflow.com/questions/314998/sql-server-2005-drop-column-with-constraints

Unfortunately without any success :( The line returned is:

fkKeywordRolleKontakt 2 814625945 0 defEmptyString

And I cannot remove either of fkKeywordRolleKontakt and defEmptyString.

What is the correct way to get rid of this dependency?

EDIT: Perhaps this is of importance too. The column fkKeywordRolleKontakt is of type udKeyword (nvarchar(50)) with default dbo.defEmptyString.


Edit 2: Solved

I could solve the problem now. I'm sorry, I did not copy the full error message, which was:

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

I could generate a script to drop the column by right-clicking on the column entry (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt) (in MSSQL Server Manager), selecting Modify and deleting the column. Then Table Designer > Generate Change Script generated the necessary commands:

ALTER TABLE dbo.tlkpRolleKontakt
    DROP CONSTRAINT FK_tlkpRolleKontakt_tlkpKeyword
EXECUTE sp_unbindefault N'dbo.tlkpRolleKontakt.fkKeywordRolleKontakt'
ALTER TABLE dbo.tlkpRolleKontakt
    DROP COLUMN fkKeywordRolleKontakt

That's it :)

+1  A: 

Did you try first:

ALTER TABLE <tablename> DROP CONSTRAINT defEmptyString;

?

Aaron Bertrand
Yes, I did. I then got a message that defEmptyString isn't a constraint on this table.
Simon A. Eugster
So what happens with this query: SELECT OBJECT_NAME(parent_object_id)FROM sys.default_constraintsWHERE name = 'defEmptyString'; -- ? Do you get a result, if so, is it this table? If you don't get a result, what about: SELECT type_desc FROM sys.objects WHERE name = 'defEmptyString'; --?
Aaron Bertrand
No result for the first one, and for the second one row:type_desc DEFAULT_CONSTRAINT
Simon A. Eugster
So sys.objects has a row, but sys.default_constraints does not? This is SQL Server 2008? Was it upgraded from 2000, and what is the compatibility level? Are you sure you are always using dbo. prefix when referencing the table that has this column? What user are you connecting as and what permissions does the user have?
Aaron Bertrand
Yes. sys.default_constraints has no row. It is SQL Server 2008, and the compatibility level is set to 2008. I'm quite sure the database itself has been run under 2000 because the code is from 2004. I'm connected as local user with (afaik) admin permissions. .dbo prefix: No, but I tested now, does not make any difference.
Simon A. Eugster
PS: Might the user defined constant (see edit in the question) cause a problem?
Simon A. Eugster
Okay, Problem solved. Sorry for the missing information, I didn't think it was important too (although I should have known better). Thank you for your answer and time!
Simon A. Eugster
The column is a user-defined type? Yes, that information certainly would have been relevant.
Aaron Bertrand
Yes, it was user-defined.
Simon A. Eugster
+1  A: 

use this script to cancel the checking of constraint :

ALTER TABLE  @tablename  NOCHECK CONSTRAINT  @constraintname 
masoud ramezani
There does not seem to be any constraint: Msg 11415, Level 16, State 1, Line 1Object 'defEmptyString' cannot be disabled or enabled. This action applies only to foreign key and check constraints.Msg 4916, Level 16, State 0, Line 1Could not enable or disable the constraint. See previous errors.
Simon A. Eugster