CASCADE
will propagate the change when the parent changes. (If you delete a row, rows in constrained tables that reference that row will also be deleted, etc.)
SET NULL
sets the column value to NULL when a parent row goes away.
RESTRICT
causes the attempted DELETE of a parent row to fail.
EDIT: You didn't ask about them, but the SQL standard defines two other actions: SET DEFAULT
and NO ACTION
. In MySQL, NO ACTION
is equivalent to RESTRICT
. (In some DBMSs, NO ACTION
is a deferred check, but in MySQL all checks are immediate.) The MySQL parser accepts SET DEFAULT
, but both the InnoDB and NDB engines reject those statements, so SET DEFAULT
can't actually be used for either an ON UPDATE
or ON DELETE
constraint.
Also, note that cascading foreign key actions do not activate triggers in MySQL.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…