USE `db`;
DELIMITER $$
CREATE TRIGGER `recintos_BDEL`
BEFORE DELETE ON recintos
FOR EACH ROW
BEGIN
DELETE FROM imagenes WHERE id_imagen IN (
SELECT imagenes_id_imagen FROM r_imagenes_recintos
WHERE recintos_id_recinto=OLD.id_recinto
);
END; $$
DELIMITER |
或者
USE `db`;
DELIMITER $$
CREATE TRIGGER `recintos_BDEL`
BEFORE DELETE ON recintos
FOR EACH ROW
DELETE FROM imagenes WHERE id_imagen IN (
SELECT imagenes_id_imagen FROM r_imagenes_recintos
WHERE recintos_id_recinto=NEW.id_recinto
);