A value is fully null if all columns are null.
Referential Integrity: A relational rule requiring foreign key values to either match a primary key value or be fully null.
Foreign keys must obey referential integrity at all times.
A composite key value is partially null if some, but not all columns are null.
A partially null composite key can never match a primary key, as primary keys cannot be null.
A null in a simple foreign key does not violate referential integrity.
Referential integrity can be violated in four ways:
Updating a primary key.
Updating a foreign key.
Inserting a row containing a primary key.
Inserting a row containing a foreign key.
Deleting a row containing a primary key does not violate referential integrity.
MySQL provides several actions to manage referential integrity violations:
RESTRICT: Rejects inserts, updates, or deletes that would violate integrity.
SET NULL: Sets invalid foreign keys to null, cannot be used if the foreign key does not allow null values.
SET DEFAULT: Sets invalid foreign keys to a predefined default value (limited support in some MySQL configurations).
CASCADE: Propagates changes from the primary key to associated foreign keys:
If a primary key is deleted, rows with matching foreign keys are also deleted.
If a primary key is updated, matching foreign keys are updated to reflect the change.
ON UPDATE and ON DELETE clauses specify the actions taken regarding foreign keys during update or delete operations.
MySQL supports only the four specified actions in these clauses.
RESTRICT is applied when ON UPDATE or ON DELETE is omitted.
SET NULL is not applicable if the foreign key cannot be null.
SET DEFAULT is limited in some MySQL setups.
Deleting a foreign key has no effect on the primary key.