延迟约束检查 [英] deferred constraint checking

查看:257
本文介绍了延迟约束检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在我们的数据库设计中,我们在两个实体之间有一个循环引用。换句话说,我们在每个表中都有引用彼此主键的外键。为了在这些表中插入记录,我们需要执行延迟约束检查。这是可能在SQL Server 2008?我知道Oracle DDL对此有特殊的语法。

Currently In our database design we have an circular reference between two entities. In other words, we have foreign keys in each table that reference each others primary key. In order to insert records in these tables we need to perform a deferred constraint checking. Is this possible in SQL Server 2008? I know Oracle DDL has special syntax for this.

推荐答案

没有本地方法在SQL Server中执行延迟约束检查。

There is no native way to do deferred constraint checking in SQL Server.

可能你最好的选择是在第一个表的外键列中插入一个NULL值,直到第二个记录被插入,然后作为同一个事务的一部分,更新第一个表中的外键列。

Likely your best option is to insert a NULL value into the foreign key column in the first table until the second record is inserted, and then as part of the same transaction, update the foreign key column in the first table.

我很感兴趣 - 您的循环引用的业务原因是什么?这绝对是一个非凡的要求。

I'm interested - what is the business reason for your circular reference? It's definitely an extraordinary requirement.

另请参阅此线程,对同一主题。

Also have a look at this thread, on the same topic.

这篇关于延迟约束检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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