1.11 Referential Integrity Flashcards
fully NULL
A fully NULL foreign key is a simple or composite foreign key in which all columns are NULL.
Referential integrity
Referential integrity is a relational rule that requires foreign key values are either fully NULL or match some primary key value.
RESTRICT constraint
RESTRICT rejects an insert, update, or delete that violates referential integrity.
Applies to primary key update and delete, and foreign key insert and update
SET NULL constraint
SET NULL sets invalid foreign keys to NULL.
Applies to primary key update and delete, and foreign key insert and update
SET DEFAULT constraint
SET DEFAULT sets invalid foreign keys to the foreign key default value.
Applies to primary key update and delete, and foreign key insert and update
CASCADE constraint
CASCADE propagates (extends/applies) primary key changes to foreign keys.
Applies to primary key update and delete only.
ON UPDATE / ON DELETE
Actions are specified in the optional ON UPDATE and ON DELETE clauses of the FOREIGN KEY constraint. ON UPDATE and ON DELETE are followed by either RESTRICT, SET NULL, SET DEFAULT, or CASCADE.
Referential integrity violations for composite foreign keys
Primary key is updated or deleted.
Foreign key is updated or inserted
What does CASCADE do when a primary key is deleted?
Rows containing matching foreign keys are deleted.
What does CASCADE do if a primary key is updated?
matching foreign keys are updated to the same value.