Erklær en henvisningshandling:PÅ SLET CASCADE, for eksempel:
CREATE TABLE user (
user_id int PRIMARY KEY
);
CREATE TABLE offer (
offer_id int PRIMARY KEY
);
CREATE TABLE user_offer (
user_id int,
offer_id int,
PRIMARY KEY (user_id, offer_id),
FOREIGN KEY (user_id) REFERENCES user (user_id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES offer (offer_id) ON DELETE CASCADE
);
Interessant nok ser det ud til, at specificering af referencehandling i "shorthand" fremmednøglesyntaks ikke virker (bekræftet under MySQL 5.5.30, 5.6.6 m9). Følgende bliver parset, men når user
er slettet, det tilsvarende user_offer
bliver ikke slettet:
CREATE TABLE user_offer (
user_id int REFERENCES user (user_id) ON DELETE CASCADE,
offer_id int REFERENCES offer (offer_id) ON DELETE CASCADE,
PRIMARY KEY (user_id, offer_id)
);