Previous Topic: DescriptionNext Topic: Data Types


Referential Actions That Conflict

A foreign key is rejected if the table involved has more than one foreign key and the referential actions of any two of those foreign keys conflict. One of two conditions are generally responsible for conflicts between referential actions:

  1. A delete on a referenced table can propagate conflicting referential actions to a row of a referencing table. For example, if two foreign keys on table A reference table B, and one foreign key specifies ON DELETE CASCADE but the other specifies ON DELETE SET DEFAULT, then it becomes impossible to update table A in a way that satisfies both foreign keys.
  2. The order in which foreign key references are followed and satisfied affects the resulting actions taken on referencing rows. It might initially seem that all situations described in the first condition (previously described) would also be included here. For example, if the SET DEFAULT described in the first condition (previously described) were executed before the CASCADE, the stored default values could effectively sever the row's other foreign key connection to the deleted row in table B, in which case the ON DELETE CASCADE would never be executed. But this second condition can occur even if the delete actions agree.

    Consider a case in which both foreign keys on table A specify ON DELETE SET NULL and the columns used in the two keys partially overlap. Setting any of the overlapping columns to NULL would sever both foreign keys' connections, because a NULL in any column of a foreign key severs the connection to the parent row. The first foreign key that is executed would therefore have its columns set to NULL, but the second foreign key would never be executed.

A table listing referential actions that conflict is provided in the following. When referring to the table, please note that it should be interpreted with regard to the following:

In the following table, the abbreviations describe CONFLICTS and represent the following:

ODR

Represents ON DELETE RESTRICT.

ODC

Represents ON DELETE CASCADE.

ODSD

Represents ON DELETE SET DEFAULT.

ODSN

Represents ON DELETE SET NULL.

OUR

Represents ON UPDATE RESTRICT.

Note: The asterisk (*) means it does not conflict if defaults for all columns involved are NULL.

REFERENTIAL ACTIONS:

ODR

ODC

ODSD

ODSN

OUR

ON DELETE RESTRICT

 

X

X

X

 

ON DELETE CASCADE

X

 

X

X

X

ON DELETE SET DEFAULT

X

X

 

X*

X

ON DELETE SET NULL

X

X

X*

 

X

ON UPDATE RESTRICT

 

X

X

X

 

Note: Foreign keys can also be rejected for reasons not mentioned here. For a complete list of reasons, see the SQL return codes section in the CA Datacom/DB Message Reference Guide.