Unable to drop constraint in SQL server 2005, “Could not drop constraint. See previous errors”

穿精又带淫゛_ 提交于 2019-12-22 05:22:08

问题


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


回答1:


I was having the same issue on SQL Server 2008 R2, I solved my problem with below line hopefully it will work for someone else as well :)

    Alter Table [Table Name]
    DROP Column [Column Name]



回答2:


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




回答3:


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.




回答4:


I had same problem.

The reason was that I made a mistake in my cursor statement, which was iterating some constraint I was to drop. So this error occurred when the constraint was actually removed in the same transaction. Then I did a rollback and checked if it existed: it did (of course, after rollback!).

Check if it really exists at the moment of dropping.



来源:https://stackoverflow.com/questions/2592977/unable-to-drop-constraint-in-sql-server-2005-could-not-drop-constraint-see-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!