DELIMITER $$ $$ CREATE TRIGGER `vn`.`dms_beforeDelete` BEFORE DELETE ON dms FOR EACH ROW BEGIN DECLARE vCanNotBeDeleted INT; SELECT COUNT(*) INTO vCanNotBeDeleted FROM dmsType dt WHERE NOT (code <=> 'trash') AND dt.id = OLD.dmsTypeFk; IF vCanNotBeDeleted THEN CALL util.throw('A dms can not be deleted'); END IF; END$$ DELIMITER ;