CREATE PROCEDURE `spDeleteContentPath` ( IN `P_ContentId` INTEGER ) BEGIN DECLARE `P_TeacherContentId` INTEGER ; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK ; SELECT ? ; END ; IF EXISTS ( SELECT ? FROM `tteacherContent` WHERE `Id` = `P_ContentId` AND `ContentLink` IS NULL ) THEN START TRANSACTION ; DELETE FROM `tteacherContent` WHERE `Id` = `P_ContentId` ; DELETE FROM `tteachercontentassign` WHERE `TeacherContentId` = `P_ContentId` ; SELECT ? ; COMMIT ; ELSE START TRANSACTION ; SET `P_TeacherContentId` = ( SELECT * FROM `tteachercontent` WHERE `REGEXP_LIKE` ( `ContentPath` , `CONCAT` ( ? , `P_ContentId` , ? ) ) ) ; DELETE FROM `tteacherContent` WHERE `Id` = `P_ContentId` OR `Id` IN ( SELECT `P_TeacherContentId` ) ; DELETE FROM `tteachercontentassign` WHERE `TeacherContentId` IN ( SELECT `P_TeacherContentId` ) ; SELECT ? ; COMMIT ; END IF ; END 