Oracle:约束,依赖于另一个表
抱歉,标题很奇怪,不知道如何更好地命名 Q。所以:
我有 3 张桌子。实体A、实体B、AB。经典的多对多实现。
是否有可能创建约束条件,要求始终在 A 和 B 之间至少具有一种关系。
示例工作流程:
a) 插入 A、插入 B、插入关系、提交; 成功
b) 插入A,插入B,提交; FALSE
所以问题是:是否有 on commit
触发器?或者类似的东西。
Sorry for weird title, don't know how to name the Q better. So:
I have 3 tables. EntityA, EntityB, AB. The classical many-to-many implementation.
Is there any possibility to create constraint that mandates ALWAYS to have at least one relation between A and B.
Example workflow:
a) Insert A, Insert B, insert relation, commit; SUCCESS
b) Insert A, Insert B, commit; FALSE
So the question is: is there any on commit
trigger? Or something similar to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不存在 ON COMMIT 触发器之类的东西。但是,您通常可以使用物化视图来模拟 ON COMMIT 触发器的行为。在您的情况下,您可以
,则在提交时引发异常,物化视图刷新发生。如果物化视图的约束失败,则提交失败。
There is no such thing as an ON COMMIT trigger. However, you can generally simulate the behavior of an ON COMMIT trigger using materialized views. In your case, you could
When you commit, the materialized view refresh takes place. If a constraint on the materialized view fails, the commit fails.
您可以在 AB 上设置延迟约束,仅在提交时检查值的有效性。
您可以在EntityA和EntityB表中设置AB表的PK以供引用,反之亦然(取决于设置的延迟约束)。
假设此插入位于同一事务中,如果 AB 表中没有有效条目,您也许可以推出更改。
You can set up deferred constraints on AB which will check for the validity of the values only on commit of the same.
You can set up the PK of AB Table in EntityA and EntityB tables for referencing or vice versa(depending on that set the deferred constraints).
Assuming this inserts are within a same transaction you maybe able to rollout the changes, if no valid entry goes into AB table.