views:

51

answers:

2

I'm trying to drop a constraint on a db table, something like:

ALTER TABLE MyTable drop CONSTRAINT FK_MyTable_AnotherTable

But the execution just runs and runs. If I stop it I see:

Msg 3727, Level 16, State 0, Line 2
Could not drop constraint. See previous errors.

Web search throws up various pages but note that the constraint is properly named and I am trying to remove it using the correct name

A: 

Verify that you've not already dropped the constraint, like:

SELECT OBJECT_ID('FK_MyTable_AnotherTable')

If this returns null, your constraint no longer exists. That would explain the error message.

Andomar
No the constraint has not already been removed, I have tried your method as well as others and it definitely still exists. It will also stop me dropping the associated column
DannykPowell
@DannykPowell: What does `object_id('FK_MyTable_AnotherTable','F')` display?
Andomar
@Andomar 1939703691
DannykPowell
See my answer, have sorted by disabling constraint first- thanks for your answer @Andomar
DannykPowell
A: 

Found a way to sort this, although I don't understand why it was necessary.

Have been able to drop the constraint by disabling it first:

ALTER MyTable NOCHECK CONSTRAINT FK_MyTable_AnotherTable

The drop then completes fine

Would still welcome any comments on the reason why this is necessary

DannykPowell