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

自作多情 提交于 2019-12-05 07:38:07

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]

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

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.

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.

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