也有刪除鏈接排,外鍵和「刪除級聯」指令一個SQL的方式:
CREATE TABLE buildings (
building_no int(11) NOT NULL AUTO_INCREMENT,
building_name varchar(255) NOT NULL,
address varchar(355) NOT NULL,
PRIMARY KEY (building_no)
) ENGINE=InnoDB;
CREATE TABLE rooms (
room_no int(11) NOT NULL AUTO_INCREMENT,
room_name varchar(255) NOT NULL,
building_no int(11) NOT NULL,
PRIMARY KEY (room_no),
KEY building_no (building_no),
CONSTRAINT rooms_ibfk_1
FOREIGN KEY (building_no)
REFERENCES buildings (building_no)
ON DELETE CASCADE
) ENGINE=InnoDB
因此,如果在「建設」表中的行被刪除,所有來自「房間」表的相關記錄也會被刪除 - 無需額外的代碼。對於mysql來說這只是與InnoDB引擎一起工作的 。