This is necessary and useful for normalized tables in order to ensure the relationship of foreign keys between them. Itβs somewhat less likely that you will change the value of the PK field, especially if it is auto_increment , but when that happens, the change cascades down through the normalized FK relationships.
Similarly, ON UPDATE DELETE is useful for cascading row deletion in all your 1:1 FK relationships, which makes it unnecessary to perform multiple deletions from application code. In any case, this can be the cause of errors.
Consider the following:
table customers: custid INT NOT NULL PRIMARY KEY, custname VARCHAR(64) NOT NULL table orders: orderid INT NOT NULL PRIMARY KEY, custid INT NOT NULL, FOREIGN KEY (custid) REFERENCES customers (custid) ON UPDATE CASCADE ON DELETE CASCADE
Suppose you need to combine records from two databases, but this will cause PK collisions. Now you can safely update all PK custid in customers in one of the databases, and all related orders are automatically reconnected with new identifiers.
source share