Cascade declarative referential integrity.To be more compliant with the SQL standard, IB extended the syntax for declarative referential integrity through foreign keys. With this feature, users are able to tell the server at the time the foreign key is defined, what should be the action performed in details tables when a record in the master table updates its primary key or the whole record is deleted.In IB4, this capability was limited to the implicit behavior of NO ACTION. This means that a PK in the master table that's referenced in a detail (child) table cannot be deleted or updated; otherwise, an error is reported. Those cases where handled in BEFORE triggers in the master table. Now, with the extension, the syntax for defining the constraint for a column at the column level, namely, inside the column definition, becomes:
and at the table level, namely, adding a constraint to the table after it has been created, becomes:
Among other advantages, this approach allows a declarative sentence that's easy to read in an script, as opposed to user defined triggers. Also, triggers have disadvantages when compared to declarative referential integrity due to the multi versioning engine. Worse, when dealing with updates to the master table's PK, the trigger approach becomes tricky. The available options for the behavior on the child table when deleting or updating the PK on the master table are:
Take into account that the cascade can be propagated among many levels of master/details relationships in the special case when the FK in the child table is part of the PK and the grandchild uses the whole PK of the child as its new FK. However, creating keys that span several fields is calling for performance problems in IB. When a PK or FK is too long due to FK propagation, it's better to use a surrogate key instead. |
This page was last updated on 2002-10-09 07:16:23 |