gpt4 book ai didi

Liquibase: difference between 'initiallyDeferred' and 'deferrable'(Liquibase:“初始延期”和“可延期”的区别)

转载 作者:bug小助手 更新时间:2023-10-24 18:10:38 31 4
gpt4 key购买 nike



I understand why the deferred parameter is needed, but the presence of two parameters 'initiallyDeferred' and 'deferrable' in the liquidbase script is a little confusing, I can’t find anything specific in the documentation except something like 'initiallyDeferred - Defines whether constraints are initially deferred' (very useful, thanks!).
What is the difference between them?

我理解为什么需要延迟参数,但是在iquidbase脚本中出现的两个参数‘InitiallyDefined’和‘deferable’有点令人困惑,我在文档中找不到任何具体的东西,除了像‘InitiallyDeferable-定义约束是否最初被延迟’这样的东西(非常有用,谢谢!)。它们之间有什么不同?


更多回答
优秀答案推荐

You didn't specify which database you use; I guess all of them - that support such options - behave the same.

您没有指定使用哪个数据库;我猜所有支持这些选项的数据库的行为都是相同的。


This is Oracle.

这是Oracle。


By default (if you don't specify anything), constraint is created as non deferrable which means that possible violation is reported at once.

默认情况下(如果您不指定任何内容),约束被创建为不可推迟,这意味着立即报告可能的违规。


On the other hand, you can choose to set it to be deferrable and - if you do - then you have two more options to specify:

另一方面,您可以选择将其设置为可推迟,如果您这样做了,那么您还有两个选项需要指定:



  • whether it is initially immediate (validation is done immediately, whenever you insert, modify or delete rows from that table) or

  • initially deferrable (which means that validation will "wait" until commit).




If you wonder when to use deferred initially deferrable constraint, then: I usually use it when two tables reference each other, i.e. have foreign key constraints that point from one table to another and vice versa.

如果您想知道什么时候使用最初可推迟的延迟约束,那么:我通常在两个表相互引用时使用它,即具有从一个表指向另一个表的外键约束,反之亦然。


It means that - if there was no such a possibility (deferring the constraint) - you wouldn't be able to insert rows into any of these tables because

这意味着--如果没有这种可能性(推迟约束)--您将无法向这些表中的任何一个插入行,因为



  • if you insert row into the 1st table, foreign key constraint would fail because parent key (in the 2nd table) doesn't exist yet

  • if you try to insert a row into the 2nd table first (hoping to circumvent the error), you wouldn't succeed because it is now parent key in the 1st table that is missing


It means that you'd have to drop or disable (at least one) foreign key constraint(s), insert rows, and enable (or crate) them back.

这意味着您必须删除或禁用(至少一个)外键约束(S),插入行,然后启用(或装箱)它们。


更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com