Disabling foreign key constraint, still can#39;t truncate table? (SQL Server 2005)(禁用外键约束,还是不能截断表?(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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:禁用外键约束,还是不能截断表?(SQL Server 2005)


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01