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)
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
