是否可以将参照完整性检查推迟到 SQL Server 中的事务结束? [英] Is it possible to defer referential integrity checks until the end of a transaction in SQL Server?

查看:26
本文介绍了是否可以将参照完整性检查推迟到 SQL Server 中的事务结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在 Fowler 的 PofEA 中读到,某些数据库引擎允许您将 RI 检查推迟到事务结束.这在 SQL Server 中可行吗?

I recently read in Fowler's PofEA that some database engines allow you to defer RI checks until the end of the transaction. Is this possible in SQL Server?

问题出现在一些场景中,我试图保存包括插入和删除在内的更改,确定执行操作的正确顺序以避免 RI 失败可能会很棘手.我知道在交易结束时 RI 会很好,因此推迟这些检查似乎是理想的.

The problem comes with some scenarios where I am trying to save changes that include insertions and deletions, it can be tricky to determine the correct order in which to perform the operations to avoid RI failures. I know that at the end of the transaction the RI will be good so it would seem ideal to defer these checks.

推荐答案

看起来 sql server 不允许这样做,但是您 不是唯一一个想要它的人.它是 SQL 92 标准的一部分,所以他们已经有 17 年的时间来弄清楚了.再说一次,MySQL 也不支持它(尽管 Oracle 支持).

Looks like sql server doesn't allow this, but you aren't the only one who wants it. It's part of the SQL 92 standard, so they've had 17 years now to figure it out. Then again, MySQL doesn't support it either (although Oracle does).

重新排列语句可能是您最好的选择.

Reordering the statements is probably your best option.

这篇关于是否可以将参照完整性检查推迟到 SQL Server 中的事务结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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