He leído esto sobre la palabra clave SQL DEFERRABLE
en Sistemas de bases de datos - El libro completo.NO DEFERRABLE versus DEFERRABLE INICIALMENTE INMEDIATO
The latter [NOT DEFERRABLE] is default, and means that every time a database modification statement is executed, the constraint is checked immediately afterwards, if the modification could violate the foreign-key constraint.
However, if we declare a constraint to be DEFERRABLE, then we have the option of having it wait until a transaction is complete before checking the constraint.
We follow the keyword DEFERRABLE by either INITIALLY DEFERRED or INITIALLY IMMEDIATE. In the former case, checking will be deferred to just before each transaction commits. In the latter case, the check will be made immediately after each statement.
¿Cómo es diferente de NOT DEFERRABLE
DEFERRABLE INITIALLY IMMEDIATE
? En ambos casos, parece que cualquier restricción se verifica después de cada declaración individual.
Debo señalar que aún estoy para ver una buen uso para 'NOT DEFERRABLE'. Todo lo que hace es causar problemas. Recomiendo usar 'DEFERRABLE INICIALMENTE INMEDIATO' de forma predeterminada. –
@romkyns: 'DEFERRABLE' indica la intención del diseñador de diferir la restricción es una acción que vale la pena o es necesaria. Este no es el caso para la gran mayoría de las restricciones de base de datos y el etiquetado como 'DEFERRABLE 'perdería esta útil distinción. – onedaywhen
@onedaywhen Un colega mío ha señalado desde entonces una buena razón válida, en realidad: puede confiar en restricciones no diferibles en cualquier punto de cualquier transacción, pero las diferibles solo se observan definitivamente al comienzo de una transacción. –