-1
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
);
4

1 回答 1

0

唯一的区别似乎是在第一个实例中使用了BEGIN ... END复合语句块(以及在第二个实例中错误更改 / 缺少结束分隔符)。

由于触发器只包含一条语句,因此不需要复合BEGIN ... END语句块——但它肯定不会造成任何伤害。也就是说,通过正确使用语句分隔符,两种方法都将获得相同的结果。

对于它的价值,我个人的偏好是使用第二个实例(即避免复合语句块,它们不是严格必要的)。

于 2013-07-13T00:10:39.983 回答