无法在SQL Server 2005中删除约束,"无法删除约束.请参阅先前的错误"

Dan*_*ell 6 sql sql-server constraints alter-table

我试图在数据库表上删除约束,例如:

ALTER TABLE MyTable drop CONSTRAINT FK_MyTable_AnotherTable
Run Code Online (Sandbox Code Playgroud)

但执行只是运行并运行.如果我停止它,我看到:

Msg 3727, Level 16, State 0, Line 2
Could not drop constraint. See previous errors.
Run Code Online (Sandbox Code Playgroud)

Web搜索会抛出各种页面,但请注意约束已正确命名,我尝试使用正确的名称将其删除

Zee*_*mal 5

我在SQL Server 2008 R2上遇到了同样的问题,我用下面的代码解决了我的问题,希望它也适用于其他人:)

    Alter Table [Table Name]
    DROP Column [Column Name]
Run Code Online (Sandbox Code Playgroud)

  • 我希望您已经为您找到了答案。我不认为线程所有者要删除任何列,他只想删除外键(也许更改列定义) (2认同)

Dan*_*ell 2

找到了一种方法来对此进行排序,尽管我不明白为什么有必要。

已经能够通过首先禁用它来删除约束:

ALTER MyTable NOCHECK CONSTRAINT FK_MyTable_AnotherTable
Run Code Online (Sandbox Code Playgroud)

然后下降就完成了

仍然欢迎任何关于为什么这是必要的评论