DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`clean`() BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; DELETE FROM ekt WHERE fec < (util.VN_CURDATE() - INTERVAL 4 YEAR); DELETE IGNORE sr.* FROM supplyResponse sr LEFT JOIN deliveryInformation di ON sr.ID = di.supplyResponseID WHERE di.LatestOrderDateTime < (util.VN_CURDATE() - INTERVAL 1 WEEK) OR di.ID IS NULL; DELETE FROM putOrder WHERE created < (util.VN_CURDATE() - INTERVAL 1 MONTH); END$$ DELIMITER ;