禁用外键约束,仍然不能截断表? (SQL Server 2005) [英] Disabling foreign key constraint, still can't truncate table? (SQL Server 2005)

查看:556
本文介绍了禁用外键约束,仍然不能截断表? (SQL Server 2005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为PX_Child的表,在PX_Parent上有一个外键。我想临时禁用此FK约束,以便我可以截断PX_Parent。我不知道这怎么回事。

I have a table called PX_Child that has a foreign key on PX_Parent. I'd like to temporarily disable this FK constraint so that I can truncate PX_Parent. I'm not sure how this goes however.

我尝试过这些命令

ALTER TABLE PX_Child NOCHECK CONSTRAINT ALL

ALTER TABLE PX_Parent NOCHECK CONSTRAINT ALL

(truncate commands)

ALTER TABLE PX_Child CHECK CONSTRAINT ALL

ALTER TABLE PX_Parent CHECK CONSTRAINT ALL

但截断仍然告诉我它不能截断PX_Parent,键约束。我已经看了所有的网络,似乎找不到我做错了,对不起,这个问题的基本性质。

But the truncate still tells me it can't truncate PX_Parent because of a foreign key constraint. I've looked all around the net and can't seem to find what I'm doing wrong, sorry for the basic nature of this question.

推荐答案

如果有任何外键引用它,则不能截断表,包括禁用的约束。您需要删除外键约束或使用 DELETE 命令。

You can't truncate the table if there is any foreign key referencing it, including disabled constraints. You either need to drop the foreign key constraints or use the DELETE command.

这篇关于禁用外键约束,仍然不能截断表? (SQL Server 2005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆